Deriving Contravariant and Profunctor

Would it be possible to add mechanisms to derive Contravariant and Profunctor instances? As with Functor, each algebraic datatype can only have one sensible instance of each of these. David Feuer

Actually it is trickier than you'd think.
With "Functor" you can pretend that contravariance doesn't exist.
With both profunctor and contravariant it is necessarily part of the puzzle.
data Compose f g a = Compose (f (g a))
* are both f and g contravariant leading to a functor?
* is f contravariant and g covariant leading to a contravariant functor?
* is f covariant and g contravariant leading to a contravariant functor?
data Wat p f a b = Wat (p (f a) b)
is p a Profunctor or a Bifunctor? is f Contravariant or a Functor?
We investigated adding TH code-generation for the contravariant package,
and ultimately rejected it on these grounds.
https://github.com/ekmett/contravariant/issues/17
-Edward
On Fri, Sep 11, 2015 at 12:49 PM, David Feuer
Would it be possible to add mechanisms to derive Contravariant and Profunctor instances? As with Functor, each algebraic datatype can only have one sensible instance of each of these.
David Feuer _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Oh, I see... you get horrible overlap problems there. Blech! I guess
they'll all act the same (modulo optimized <$ and such), but GHC can't
know that and will see them as forever incoherent.
On Fri, Sep 11, 2015 at 1:52 PM, Edward Kmett
Actually it is trickier than you'd think.
With "Functor" you can pretend that contravariance doesn't exist.
With both profunctor and contravariant it is necessarily part of the puzzle.
data Compose f g a = Compose (f (g a))
* are both f and g contravariant leading to a functor? * is f contravariant and g covariant leading to a contravariant functor? * is f covariant and g contravariant leading to a contravariant functor?
data Wat p f a b = Wat (p (f a) b)
is p a Profunctor or a Bifunctor? is f Contravariant or a Functor?
We investigated adding TH code-generation for the contravariant package, and ultimately rejected it on these grounds.
https://github.com/ekmett/contravariant/issues/17
-Edward
On Fri, Sep 11, 2015 at 12:49 PM, David Feuer
wrote: Would it be possible to add mechanisms to derive Contravariant and Profunctor instances? As with Functor, each algebraic datatype can only have one sensible instance of each of these.
David Feuer _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

They'd all act the same assuming any or all of the instances existed, but
GHC can't backtrack and figure out which way to get there, it'll only look
at the instance head.
-Edward
On Fri, Sep 11, 2015 at 2:22 PM, David Feuer
Oh, I see... you get horrible overlap problems there. Blech! I guess they'll all act the same (modulo optimized <$ and such), but GHC can't know that and will see them as forever incoherent.
Actually it is trickier than you'd think.
With "Functor" you can pretend that contravariance doesn't exist.
With both profunctor and contravariant it is necessarily part of the
On Fri, Sep 11, 2015 at 1:52 PM, Edward Kmett
wrote: puzzle. data Compose f g a = Compose (f (g a))
* are both f and g contravariant leading to a functor? * is f contravariant and g covariant leading to a contravariant functor? * is f covariant and g contravariant leading to a contravariant functor?
data Wat p f a b = Wat (p (f a) b)
is p a Profunctor or a Bifunctor? is f Contravariant or a Functor?
We investigated adding TH code-generation for the contravariant package,
and
ultimately rejected it on these grounds.
https://github.com/ekmett/contravariant/issues/17
-Edward
On Fri, Sep 11, 2015 at 12:49 PM, David Feuer
wrote: Would it be possible to add mechanisms to derive Contravariant and Profunctor instances? As with Functor, each algebraic datatype can only have one sensible instance of each of these.
David Feuer _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (2)
-
David Feuer
-
Edward Kmett