flexible contexts and context reduction

Tom Schrijvers Tom.Schrijvers at cs.kuleuven.be
Thu Mar 27 04:55:08 EDT 2008


> You're talking about something else: the dictionaries (Ord a, Ord b) from which the Ord (a,b) dictionary were constructed.  We don't have a very good name for these guys, but "superclass" isn't a good one.
>
> Otherwise I agree with all you say. Your idea of using type families is cool.
>
> |         data OrdDict a =
> |                 { (<) :: a -> a -> Bool
> |                  , ...
> |                 , super :: Super a
> |                 }
> |
> |         type family Super a :: *
> |         type instance Super Int   = ()
> |         type instance Super [a]   = OrdDict a
> |         type instance Super (a,b) = (OrdDict a, OrdDict b)
> |
> | A similar solution is possible with a data family Super (but obviously I'm
> | in favor of type families :)
>
> Can you say why?  A data family would work fine here.  But it's not a big deal.

Just a matter of taste, and familiarity.

> So the other question is whether this is useful. How often do people write stuff like this?
>        f :: Ord [a] => a -> a -> Bool
>        f x y = x>y

This paper has some examples, I believe:
Modular Generic Programming with Extensible Superclasses
Martin Sulzmann and Meng Wang
In Workshop on Generic Programming (WGP'06)
http://www.comp.nus.edu.sg/~sulzmann/publications/wgp06-modulargeneric.ps

> Nevertheless, I hadn't realised it was possible before, and now I can see it is.

I'd be nice to know of people who need or would like to have this feature.

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: tom.schrijvers at cs.kuleuven.be
url: http://www.cs.kuleuven.be/~toms/



More information about the Glasgow-haskell-users mailing list