summaryrefslogtreecommitdiff
path: root/progs/demo/fact.hs
blob: 054183e26519d3cd32f70a4f78175a6686e91fc3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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