Skip to content

Instantly share code, notes, and snippets.

@ion1
Last active June 26, 2016 03:51
Show Gist options
  • Save ion1/18acf9350c40404f81e01e7708820fcd to your computer and use it in GitHub Desktop.
Save ion1/18acf9350c40404f81e01e7708820fcd to your computer and use it in GitHub Desktop.
((a -> b) -> c) -> (d -> (e -> f))
->
/ \
-> ->
/ \ / \
-> c d ->
/ \ / \
a b e f
import Data.Functor.Contravariant
data Foo a = Foo (a -> Integer)
data Bar a = Bar ((a -> Integer) -> Integer)
data Baz a = Baz (((a -> Integer) -> Integer) -> Integer)
foo :: (b -> a) -> (a -> Integer) -> (b -> Integer)
foo f g = _
bar :: (a -> b) -> ((a -> Integer) -> Integer) -> ((b -> Integer) -> Integer)
bar f g = _
baz :: (b -> a) -> (((a -> Integer) -> Integer) -> Integer) -> (((b -> Integer) -> Integer) -> Integer)
baz f g = _
instance Contravariant Foo where
contramap f (Foo g) = Foo (foo f g)
instance Functor Bar where
fmap f (Bar g) = Bar (bar f g)
instance Contravariant Baz where
contramap f (Baz g) = Baz (baz f g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment