[Haskell-cafe] Have you seen this functor/contrafunctor combo?
conal at conal.net
Wed Jun 6 03:54:26 CEST 2012
> newtype Q p a = Q (p a -> a)
> instance ContraFunctor p => Functor (Q p) where
> fmap h (Q w) = Q (h . w . cmap h)
using "cmap" for contravariant map. For instance, p a = u -> a.
> instance ContraFunctor p => Applicative (Q p) where
> pure a = Q (pure a)
> Q fs <*> Q as = Q (\ r ->
> f = fs (cmap ($ a) r)
> a = as (cmap (f $) r)
> f a)
I've checked the functor laws but not the applicative laws, and I haven't
looked for a Monad instance.
Or extend to a more symmetric definition adding a (covariant) functor f to
the contravariant functor p.
> newtype Q' p f a = Q' (p a -> f a)
A (law-abiding) Functor instance is easy, but I don't know about an
Have you seen Q or Q' before? They look like they ought to be something
familiar & useful.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe