From 4e987026148fe65c323afbc93cd560c07bf06b3f Mon Sep 17 00:00:00 2001 From: Yale AI Dept Date: Wed, 14 Jul 1993 13:08:00 -0500 Subject: Import to github. --- progs/demo/fact.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 progs/demo/fact.hs (limited to 'progs/demo/fact.hs') 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 + -- cgit v1.2.3