[Haskell-cafe] Have you seen this functor/contrafunctor combo?

Conal Elliott conal at conal.net
Thu Jun 7 17:21:18 CEST 2012


Oh, yeah. Thanks, Sjoerd.

I wonder if there's some way not to require Monad. Some sort of
ApplicativeFix instead. Hm.

-- Conal

On Wed, Jun 6, 2012 at 2:43 PM, Sjoerd Visscher <sjoerd at w3future.com> wrote:

> If there would be a package where this could be in it would be
> contravariant[1], but it isn't.
>
> > > newtype Q' p f a = Q' (p a -> f a)
>
> This compiles:
>
> > instance (Contravariant p, Functor m, MonadFix m) => Applicative (Q' p
> m) where
> >   pure a = Q' (pure (return a))
> >   Q' fs <*> Q' as = Q' $ \r -> do
> >     rec
> >       f <- fs (contramap ($ a) r)
> >       a <- as (contramap (f $) r)
> >     return $ f a
>
> [1] http://hackage.haskell.org/package/contravariant
>
> --
> Sjoerd Visscher
> https://github.com/sjoerdvisscher/blog
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120607/11559608/attachment.htm>


More information about the Haskell-Cafe mailing list