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

2012-06-09 Thread Edward Kmett
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

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

2012-06-09 Thread Edward Kmett
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

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

2012-06-07 Thread Conal Elliott
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

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

2012-06-07 Thread Sjoerd Visscher
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

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

2012-06-06 Thread Sjoerd Visscher
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

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

2012-06-05 Thread Conal Elliott
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 =