Created
April 29, 2017 18:32
-
-
Save akhileshs/a7b2472e57e58239ab28b7b34f902683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contravariant f where | |
fmap :: (b -> a) -> f a -> f b | |
newtype Predicate a = Predicate { runPredicate :: a -> Bool } | |
instance Contravariant Predicate where | |
fmap f (Predicate a) = Predicate (a . f) | |
data MyOrdering = LT | EQ | GT | |
newtype Comparison a = | |
Comparison { runComparison :: a -> a -> MyOrdering } | |
instance Contravariant Comparison where | |
fmap f (Comparison c) = Comparison (\a b -> c (f a) (f b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment