[Haskell] Re: Parameterized Show
ger at informatik.uni-bremen.de
Mon Nov 15 06:15:35 EST 2004
Graham Klyne wrote (snipped):
> I like the principle of parameterizing Show to allow for different encoding
> environments (indeed, I had wondered as I was writing my earlier message if
> the two cases were really sufficient). Indeed, in the application area
> that interests me (Semantic Web) it could be beneficial to have different
> encoding options corresponding to different serializations of RDF (e.g.
> RDF/XML and Notation3).
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).
In general I suspect you can do this without even having to extend the existing
Haskell typesystem very far. The following language extensions seem sufficient.
(1) for a class declaration, a way of declaring that a certain type represents
a dictionary of functions for that class, for example
class Show a (ShowDict,appFn) where
would define the new class "Show" but also the new type (ShowDict a) representing
dictionaries for that class. It also declares a value appFn which I shall explain
in a moment.
(2) for an instance declaration, a way of "naming" the corresponding dictionary.
instance Show Int (intShowDict) where
would create a value "intShowDict :: ShowDict Int"
(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
More information about the Haskell