]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl
Automatic execution of SCL tests in Maven
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / ShortcutFusion.scl
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl
new file mode 100644 (file)
index 0000000..6423ecb
--- /dev/null
@@ -0,0 +1,25 @@
+data List a = Nil | Cons a (List a)\r
+\r
+@private\r
+@inline\r
+build :: (forall a. a -> (b -> a -> a) -> a) -> List b\r
+build f = f Nil Cons\r
+\r
+@private\r
+foldr :: (a -> b -> b) -> b -> List a -> b\r
+foldr cons nil Nil = nil\r
+foldr cons nil (Cons h t) = cons h (foldr cons nil t)\r
+\r
+@private\r
+@inline\r
+singleton :: a -> List a\r
+singleton x = build (\nil cons -> cons x nil)\r
+\r
+@private\r
+@inline\r
+last :: List a -> a -> a\r
+last l def = foldr (\x _ -> x) def l\r
+\r
+main = last (singleton "Hello") "Foo"\r
+--\r
+Hello
\ No newline at end of file