[Haskell-cafe] lists as instances of a class?

Greg Buchholz haskell at sleepingsquirrel.org
Mon Jul 10 11:20:02 EDT 2006

David Roundy wrote:
> I'm sure I'm missing something lame here, but can someone tell me why
> we apparently can't declare a list to be an instance of a class in
> Haskell 98?

    I think it is a "feature" of H98 intended to disallow any
possibility of overlapping instances.  If you have...

    instance Vec [Double]

...there's nothing from stopping you from also declaring...

    instance Num a => Vec [a]

...but since Double is a member of Num, which instance should the
compiler use?

> Or is there perhaps some other syntax by which I'd declare
> this instance? 

    Not by the looks of section 4.3.2 of the Haskell Report (at least by
my reading).

Greg Buchholz

More information about the Haskell-Cafe mailing list