1 import "JavaBuiltin" as Java
\r
3 class Functor f where
\r
4 map :: (a -> b) -> f a -> f b
\r
8 instance Functor Foo where
\r
9 map f (Foo x) = Foo (f x)
\r
11 instance Functor Maybe where
\r
12 map f Nothing = Nothing
\r
13 map f (Just x) = Just (f x)
\r
15 data List a = Nil | Cons a (List a)
\r
17 instance Functor List where
\r
19 map f (Cons h t) = Cons (f h) (map f t)
\r
21 main = map (map (Java.iadd 1)) (Cons Nothing (Cons (Just (1 :: Integer)) Nil))
\r
23 (Cons null (Cons 2 Nil))