[Haskell-cafe] Trouble with record syntax and classes
ajb at spamcop.net
ajb at spamcop.net
Mon Feb 26 21:17:41 EST 2007
G'day all.
Quoting Aaron McDaid <aaron at aaronmcdaid.com>:
> 'class' in Haskell doesn't mean the same as 'class' in C++ or Java. I
> found it easier at first to thing of them as:
> A Haskell 'class' is more like a Java interface.
> Haskell types are more like what you might think of as 'class'es.
> Haskell 'instance' means Java 'implement'
> There is no word that means that same as 'instance' from Java/C++
> terminology. I suppose we would call them 'values' or something.
> Somebody more knowledgeable can describe the etymology of the terms,
> but these 3 observations should help.
When you type "class Foo" in Java or C++, it does three things:
1. It declares a new type called "Foo".
2. It declares a _set_ of types (i.e. a "class").
3. It declares that the type Foo (and all of its subtypes) is a member
of the set of types Foo.
In Haskell, these three operations are distinct.
1. You declare a new type using "data" or "newtype".
2. You declare a new set of types using "class".
3. You declare that a type is a member of a class using "instance".
Cheers,
Andrew Bromage
More information about the Haskell-Cafe
mailing list