[Haskell-cafe] Re: Generic types
Cale Gibbard
cgibbard at gmail.com
Tue Jun 14 03:59:43 EDT 2005
On 14/06/05, Adde <adde at trialcode.com> wrote:
> While we're at it, I tried adding a class Length in between Unit and Meter, like
> this:
>
> class Unit u where
> shortName :: u -> String
>
> class (Unit u) => Length u
>
> instance Length Meter where
> shortName u = "m"
>
> >From the information I can find on the web subclassing should include all
> of the methods in the superclasses but I get this error:
>
> `shortName' is not a (visible) method of class `Length'
>
It's saying that shortName isn't a method of the class Length, which
is right, it's a method of the class Unit, so you should put it in the
Unit instance rather than in the Length instance.
The declarations in an instance of a class C may contain bindings only
for the class methods of C. The class methods of C are exactly those
whose type signatures are given in the class declaration of C (which
may not overlap with other class declarations or top level bindings).
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list