]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Functor.scl
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Functor.scl
1 import "JavaBuiltin" as Java
2
3 class Functor f where
4     map :: (a -> b) -> f a -> f b
5     
6 data Foo a = Foo a
7
8 instance Functor Foo where
9     map f (Foo x) = Foo (f x)
10     
11 instance Functor Maybe where
12     map f Nothing = Nothing
13     map f (Just x) = Just (f x)
14     
15 data List a = Nil | Cons a (List a)
16
17 instance Functor List where
18     map f Nil = Nil
19     map f (Cons h t) = Cons (f h) (map f t)
20     
21 main = map (map (Java.iadd 1)) (Cons Nothing (Cons (Just (1 :: Integer)) Nil))
22 --
23 (Cons null (Cons 2 Nil))