[Haskell-beginners] Context reducion Stack overflow

Marco Túlio Gontijo e Silva marcot at holoscopio.com
Tue May 5 14:07:16 EDT 2009


Em Ter, 2009-05-05 às 11:33 -0400, Brent Yorgey escreveu:
> On Tue, May 05, 2009 at 10:28:10AM -0300, Marco Túlio Gontijo e Silva wrote:
> > 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]
> 
> I don't follow.  In order to get 
>  
>   instance M (IORef [a]) a
> 
> from
> 
>   instance (F f, M m (f a)) => M m a
> 
> would require
> 
>   instance M (IORef [a]) (f a)
> 
> for some f, which you don't have.

Yes, I have this instance defined for f = []:

instance M (IORef [a]) [a]

which is a instance of:

instance M (IORef a) a

> I might try rewriting M as
> 
>   class M f a where
>     mm :: (a -> a) -> f a -> IO ()
> 
> and then your automatic lifting instance would be something like
> 
>   instance (F f, M f2 a) => M (f :.: f2) a
> 
> where :.: denotes functor composition.

Ok, I think this is another possibility.  But how could I define :.:?

Greetings.


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




More information about the Beginners mailing list