[Haskell-beginners] Context reducion Stack overflow
Brent Yorgey
byorgey at seas.upenn.edu
Tue May 5 11:33:58 EDT 2009
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.
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.
-Brent
More information about the Beginners
mailing list