blob: 2e00031c4e8cc3eb8abab6c6ae16fb6976ce5522 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
-- Haskell only has covariant functors of the following form:
-- class Functor f where
-- fmap:: (a->b) -> f a -> f b
-- Contra/Co-variant :
-- http://www.reddit.com/r/haskell/comments/1cht4v/what_does_coalgebra_mean_in_the_context_of/c9gzulr
class Contravariant f where
contramap :: (a->b) -> f b -> f a
data Cont a = Cont (a -> Int)
instance Contravariant Cont where
contramap f (Cont x) = Cont (x.f)
-- The following however is covariant
data H t = H1 t | H2 ((t -> Int) -> Int)
instance Functor H where
fmap f (H1 x) = H1 (f x)
fmap f (H2 g) = H2 (\h -> g (h . f))
|