[Haskell] Re: Parameterized Show

Keith Wansbrough Keith.Wansbrough at cl.cam.ac.uk
Mon Nov 15 07:20:04 EST 2004

George Russell wrote:

> I like the idea too, not just for Show but for any instances.  It seems to
> me that in general you should be able to combine the convenience of the
> Haskell type system with the power of Standard ML's structures and functors.
> Something along these lines was done by Kahl & Scheffczyk ("Named Instances for
> Haskell Type Classes", Haskell Workshop 2001).
> (3) a way of using the dictionary.  For this we need (appFn), declaraed by the type
> declaration.  appFn has the unorthodox type
>     appFn :: ShowDict a -> (forall a . Show a => b) -> b

I've wanted this too.  Amongst other things, it would subsume all the
"fooBy" functions in the prelude and libraries - instead of having
both sort and sortBy, you could just build an Ord dictionary and pass
it to sort.

Note that there should be a way of creating a dictionary without
creating an ordinary instance - in the OP's application, you would
want two intShowDicts, one of which showed in decimal and the other of
which showed in hex.  In Haskell you can't have two instance
declarations for the same type...

--KW 8-)

More information about the Haskell mailing list