Hi Matt,

The problem you describe is not uncommon.  It's been a restriction
with constructor classes since they were first introduced.  In fact
it's actually the key to making constructor classes tractable.  You
might find that the following back issue from the Haskell list gives
you some more insight on this question.  (If the Haskell list had a
FAQ, this would surely be on it by now!):

   http://www.mail-archive.com/[email protected]/msg05356.html

(Thanks to Sven Panne who posted this URL in a previous message)

| I'm stuck.  I'd like to do this:
| 
|     instance Functor (a->b->) where
|         fmap g f x y = g (f x y)
| 
| ...but of course it has invalid syntax.  I can't think of a way to write
| (a->b->) in the ((->) a) form.  (a->b->c) would be ((->) a ((->) b c)).

One way to deal with this might be to collapse the two parameters of
type a and b into a pair of type (a,b) and then use the Functor
((a,b) ->) instead of (a->b->).  Other than that, something like
your newtype code is the only real option.  Functional dependencies
can't help here either because Functor isn't (and shouldn't be)
defined as a multiple parameter class.

In fact you can start to see why the example you have here causes
problems if you think about how you would match up a type of the
form  a -> b -> c  with the application of a functor  f t.  There
are just too many choices!

   (a -> b -> c)
    = (a ->) (b -> c)
    = (a -> b ->) c
    = Id (a -> b -> c)
    = (\a. a -> b -> c) a
    = ... etc ...

Hope this helps!

All the best,
Mark


Reply via email to