]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/RecursiveContext.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / tests / org / simantics / scl / compiler / tests / scl / RecursiveContext.scl
diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/RecursiveContext.scl b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/RecursiveContext.scl
new file mode 100644 (file)
index 0000000..7412862
--- /dev/null
@@ -0,0 +1,23 @@
+import "JavaBuiltin" as Java\r
+\r
+infixl 6  (+), (-)\r
+\r
+class Num a where \r
+    (+) :: a -> a -> a\r
+    (-) :: a -> a -> a\r
+    isZero :: a -> Boolean\r
+    one :: a     \r
+    \r
+instance Num Integer where\r
+    x + y = Java.iadd x y\r
+    x - y = Java.isub x y\r
+    isZero x = Java.icmpeq Java.iconst_0 x\r
+    one = Java.iconst_1\r
+  \r
+even x = if isZero x then True else odd (x - one)\r
+odd x = if isZero x then False else even (x - one)   \r
+    \r
+main = odd (8 :: Integer)\r
+--\r
+false\r
+\r