summaryrefslogtreecommitdiff
path: root/progs/demo/fact.hs
diff options
context:
space:
mode:
authorYale AI Dept <ai@nebula.cs.yale.edu>1993-07-14 13:08:00 -0500
committerDuncan McGreggor <duncan.mcgreggor@rackspace.com>1993-07-14 13:08:00 -0500
commit4e987026148fe65c323afbc93cd560c07bf06b3f (patch)
tree26ae54177389edcbe453d25a00c38c2774e8b7d4 /progs/demo/fact.hs
Import to github.
Diffstat (limited to 'progs/demo/fact.hs')
-rwxr-xr-xprogs/demo/fact.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/progs/demo/fact.hs b/progs/demo/fact.hs
new file mode 100755
index 0000000..054183e
--- /dev/null
+++ b/progs/demo/fact.hs
@@ -0,0 +1,14 @@
+{- This is a simple factorial program which uses the I/O system
+ to read the input and print the result -}
+
+module Main where
+
+fact :: Integer -> Integer
+fact 0 = 1
+fact (n+1) = (n+1)*fact n
+fact _ = error "Negative argument to factorial"
+
+main = appendChan stdout "Type in N: " abort $
+ readChan stdin abort $ \ input ->
+ appendChan stdout (show (fact (read (head (lines input))))) abort done
+