[Haskell-cafe] confusion about 'instance'....
Jules Bean
jules at jellybean.co.uk
Thu Jan 10 09:22:06 EST 2008
Nicholls, Mark wrote:
>
> My confusion is not between OO classes and Haskell classes, but exactly
> are the members of a Haskell type class...I'd naively believed them to
> be types (like it says on the packet!)...but now I'm not so sure.
>
Which packet?
Classes are not types.
Classes are groups of types. Sets of types. Classifications of types.
For any type, you can ask the quesiton "is this type a member of this
class, or not?"
Without wishing to split hairs too finely, I find it a useful intuition
not to consider the class context "part of the type" somehow.
So, when you see this:
(Num a, Eq b) => a -> b -> a
Rather than thinking of that whole thing as a type, it helps to think of
the part on the right of the => as the 'actual type' and the part on the
left of the => as "some extra constraints on the type".
So you might say this has the type "a -> b -> a", providing that a is a
Num and b is an Eq.
Jules
More information about the Haskell-Cafe
mailing list