[Haskell-cafe] Re: Typeclass question

Tom Pledger tom at pledger.gen.nz
Sat Dec 27 15:21:16 EST 2008


Andrew Wagner <wagner.andrew <at> gmail.com> writes:

> 
> I'm sure there's a way to do this, but it's escaping me at present. I  
> want to do something like this:
> 
> data Foo = Bar a => Foo a Bool ...
> 
> That is, I want to create a new type, Foo, whose constructor takes  
> both a Boolean and a value of a type of class Bar.


Sometimes it's enough to declare

    data Foo a = Foo a Bool

and to put the 'Bar a =>' context onto the functions and instances that
involve Foo.

For example, in Chris Okasaki's book Purely Functional Data Structures,
the h in

    data BootstrapHeap h a = ...

is always meant to satisfy 'Heap h =>', but this is ensured by putting
the context at all the points where a BootstrapHeap is created, and not
exporting BootstrapHeap's data constructors.

Regards,
Tom




More information about the Haskell-Cafe mailing list