[Haskell] Re: Parameterized Show
Ralf.Laemmel at cwi.nl
Mon Nov 15 08:58:21 EST 2004
Tomasz Zielonka wrote:
>BTW, This thread reminds me a similar problem that was discussed on
>haskell list. Unfortunately, there were some problems with this approach
>(accumulating typeclass contexts).
Yes, quite relevant.
In "Scrap your boilerplate", we had the strong version of this problem.
Say, one would want to provide type-specific instances for some generic
function, which however seemed impossible in the view of the Data methods
whose types only mention the Data (and Typeable) class. (So while run-time
type case via cast, mkT, etc. would be easy, it was unclear how to do static
and modular type-case.)
The problem is solved now!
The Data class subclasses a dedicated customisation class, we call this
for now. This is a two-parameter class; one param for the property (which is
a type constructor of kind * -> *), and another for the type at hand.
class context is propagated during descent into substructures by
the type of the method gfoldl.
The general pattern of class context parameterisation is of course not
restricted to SYB.
The SYB site (FAQ, last item) provides details including a longer code
More information about the Haskell