[Haskell-cafe] Polymorphic algebraic type constructors

Ralf Laemmel Ralf.Laemmel at cwi.nl
Wed Jun 23 14:00:35 EDT 2004

Hi Graham,

Graham Klyne wrote:

> It's been a while since I looked at the "boilerplate" work, but 
> looking at your code I think it depends on gmapQ of the polymorphic 
> value to be converted.  Does your generic Haskell processor generate 
> this automagically?

One needs Data and Typeable instances which are automagically derived by 
GHC, indeed.
(The code I sent relies on GHC CVS as of months ago. GHC 6.2's 
Data/Generics uses some different names in a few spots.)

> Anyway, it reminds me of a private communication I received on this 
> topic, suggesting that the "problem" could be resolved by making the 
> polymorphic container type an instance of Functor, and using fmap to 
> do the conversion.  This ensures that the other constructors only need 
> to be mentioned once (in the fmap instance).

As you probably notice, "Either" would require a *bifunctor*.
Unless you fix the last argument as variation point.
And then, the bmap would take two argument functions.
One would be the id function in your instance.


More information about the Haskell-Cafe mailing list