summaryrefslogtreecommitdiff
path: root/progs/demo/fact.hs
diff options
context:
space:
mode:
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
+