Reputation: 43
Im trying to print the value of a factorial function however it does not work.
fac n = if n < 2 then 1 else n * fac (n-1)
main = do
putStrLn "Enter a number: "
number <- getLine
print $ number >>= fac
Upvotes: 0
Views: 93
Reputation: 335
I don't think you need the (>>=) there. Just
print $ fac number
should be enough. However, number
needs to be an Int
or Integer
. So you either need to use read
, or, much simpler, instead of using getLine
, use readLn
, which will do getLine
and automatically convert it to an Integral type.
Upvotes: 1