
16 Dec
2016
16 Dec
'16
9:46 a.m.
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