[Haskell-study] Ch. 3: Named types and type classes
Jim Blandy
jimb at red-bean.com
Mon Nov 30 13:32:52 CST 2009
It was initially a surprise to me that f's definition is not
permitted, while g's is:
type Point = (Num n) => (n,n)
f :: Point -> Point
f x = x
g :: (Num n) => (n,n) -> (n,n)
g x = x
Basically, f would need to get a polymorphic type with a type variable
qualified with (Num n): the qualification would have to "float up"
from Point to f. And that doesn't happen. The following is okay,
too:
type Point n => (n,n)
h :: (Num n) => Point n -> Point n
h x = x
But at some point (hah!) you just don't care.
Taken together with the let-bound polymorphism thing David ran into,
the types have been more invasive than I expected them to be.
However, I write 'x:y:z' instead of '(x:y):z' often enough that I
expect I come out ahead.
More information about the Haskell-study
mailing list