
27 Oct
2014
27 Oct
'14
4:47 p.m.
Prelude> let f x = x * 2 Prelude> :t f f :: Num a => a -> a The typeclass Num is defined like this: class Num a where (+), (-), (*) :: a -> a -> a ... ...which means that the operator (*) expects two parameters of type a and returns a value of type a. Since the definition of expr looks like this: Prelude> let f x = x * 2 ...and 2 is an Int, I would expect that the type inferred for (*) is (Int -> Int -> Int) and thus f should be (Int -> Int) Can somebody explain this? Thanks!