[Haskell-cafe] Re: Instances of constrained datatypes

John Hughes rjmh at cs.chalmers.se
Thu Apr 7 09:03:53 EDT 2005


>
>
>This is a contrived example, but contains the essence of what I'd like 
>to do.  Suppose I have this datatype:
>
> > data (Eq v) => EqList v = EqList [v]
>
>I'd like to make it an instance of Functor.  However, fmap takes an 
>arbitrary function  of type a -> b.  I need an Eq constraint on a and 
>b.  Is there any way to do this without creating my own `EqFunctor' 
>class with explicitly-kinded quantification:
>
> > class (Eq a) => EqFunctor (f :: * -> *) a where
> >  eqfmap:: (Eq b) => (a -> b) -> f a -> f b
>
>Thanks.
>
>-Arjun
>
>
>
>  
>
I wrote a paper proposing an extension to allow this, published at the 
Haskell Workshop in 1999. Here's the link:

http://www.cs.chalmers.se/~rjmh/Papers/restricted-datatypes.ps

Getting the right dictionaries to the right place involves adding a 
concept of well-formed types, which perhaps is why it hasn't been taken 
up by the Simons...

John Hughes


More information about the Haskell-Cafe mailing list