Next | Atypical Types | 45 |
fact :: | (Num a) => a -> a |
n :: | (Num a) => a |
fact 0 = 1 fact n = n * fact(n-1)
"Okay, everything checks out!"
And if you ask it, it will tell you the type of fact:
fact :: (Num a) => a -> a
If you ask for the factorial of an Integer, you get back an Integer
If you ask for the factorial of a Float, you get back a Float
If you ask for the factorial of a String, you get a compile-time error
Because String is not an instance of Num
Next | Copyright © 1999,2008 Mark Dominus |