From a quick test, this is apparently due to the fact that the product not strict, and the thunks chain causes an error.
In the prelude, product is defined as:
product = foldl (*) 1
If in ghci you define it as:
> :m + Data.List > let product = foldl' (*) 1 > let fac n = product [1..n]
Then it should work. I suspect that when you specify the type signature, maybe some kind of optimization starts, which is not otherwise ... but did not stick into it.
Btw, you do not need the string let fac 0 = 1 .
source share