Here is a considerably longer worked example using the analogy to J,
borrowing heavily from Wadler:
As J, this doesn't really add any power, but perhaps when used with
non-representable functors like Equivalence/Comparison you can do something
more interesting.
-- Used for Hilbert
{-# LANGUAGE
As an aside, the Union constraint on epsilon/gepsilon is only needed for
the :+: case, you can search products just fine with any old contravariant
functor, as you'd expect given the existence of the Applicative.
-Edward
On Sat, Jun 9, 2012 at 6:28 PM, Edward Kmett ekm...@gmail.com wrote:
Here
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 sjo...@w3future.com wrote:
If there would be a package where this could be in it would be
contravariant[1], but it
On Jun 7, 2012, at 5:21 PM, Conal Elliott wrote:
Oh, yeah. Thanks, Sjoerd.
I wonder if there's some way not to require Monad. Some sort of
ApplicativeFix instead. Hm.
Something like this:
instance (Contravariant p, ApplicativeFix f) = Applicative (Q' p f) where
pure a = Q' (pure (pure
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
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 =