Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created April 29, 2017 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshs/a7b2472e57e58239ab28b7b34f902683 to your computer and use it in GitHub Desktop.
Save akhileshs/a7b2472e57e58239ab28b7b34f902683 to your computer and use it in GitHub Desktop.
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