Move Data.Functor.Contravariant into base
Mario Blažević
mblazevic at stilo.com
Fri Dec 16 14:46:31 UTC 2016
On 2016-12-13 04:45 PM, Edward Kmett wrote:
> To Andreas point, one issue with contravariant in base is that there are
> no types in base that would serve as reasonable instances. You'd get a
> scattershot pile of mostly 'nonsensical' instances for stuff like the
> GHC.Generics types.
We could add a non-nonsensical¹ instance easily enough:
> newtype Flip f a b = Flip {flipBack :: f b a}
>
> instance Contravariant (Flip (->) a) where
> contramap f (Flip g) = Flip (g . f)
Or, if FlexibleInstances are a problem:
> newtype Inverse a b = Inverse {applyInverse :: b -> a}
>
> instance Contravariant (Inverse a) where
> contramap f (Inverse g) = Inverse (g . f)
(¹): apparently sensical is not a word, which is nonsensible
More information about the Libraries
mailing list