[Haskell-cafe] Re: Generic types
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
> 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
More information about the Haskell-Cafe