import "JavaBuiltin" as Java class Functor f where map :: (a -> b) -> f a -> f b data Foo a = Foo a instance Functor Foo where map f (Foo x) = Foo (f x) instance Functor Maybe where map f Nothing = Nothing map f (Just x) = Just (f x) data List a = Nil | Cons a (List a) instance Functor List where map f Nil = Nil map f (Cons h t) = Cons (f h) (map f t) main = map (map (Java.iadd 1)) (Cons Nothing (Cons (Just (1 :: Integer)) Nil)) -- (Cons null (Cons 2 Nil))