> 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 ->
> let
> f = fs (cmap ($ a) r)
> a = as (cmap (f $) r)
> in
> 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 Applicative instance.
Have you seen Q or Q' before? They look like they ought to be something familiar & useful.
-- Conal