[Haskell-beginners] Context reducion Stack overflow

Marco Túlio Gontijo e Silva marcot at holoscopio.com
Tue May 5 09:28:10 EDT 2009


Em Seg, 2009-05-04 às 15:54 -0400, Brent Yorgey escreveu:
> On Mon, May 04, 2009 at 11:59:54AM -0300, Marco Túlio Gontijo e Silva wrote:
> 
> > > instance (F f, M m (f a)) => M m a where
> > >   mm f v = mm (m f) v
> 
> Perhaps you mean
> 
>   instance (F f, M m a) => M m (f a) where ...
> 
> ?

No, I really meant what I wrote.  An example: If I the instances I
wrote:

> instance F [] where
>   m = map

> instance M (IORef a) a where
>   mm = flip modifyIORef

I want to define:

> instance M (IORef [a]) a where
>   mm f v = mm (m f) v

This could of course be written as:

mm = mm . m

I'd like to get this last instance automaticly from that definition,
having:

f = []
m = IORef [a]

> What you have written means that to have an instance M m a, you must
> have an instance M m (f a), for which you must have an instance M m (f
> (f a)), for which you must have an instance M m (f (f (f a)))...

After this explanation I think I located the problem.  My problem seems
to be with how IncoherentInstances work, by picking always the most
generic instance.

Thanks for that.  Do you know if there a way to get around this, maybe
using another GHC extension?

Greetings.
-- 
marcot
http://marcot.iaaeee.org/




More information about the Beginners mailing list