X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FShortcutFusion.scl;fp=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FShortcutFusion.scl;h=6423ecbef3e7689c83a1ee73786731d706c18f71;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl new file mode 100644 index 000000000..6423ecbef --- /dev/null +++ b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/ShortcutFusion.scl @@ -0,0 +1,25 @@ +data List a = Nil | Cons a (List a) + +@private +@inline +build :: (forall a. a -> (b -> a -> a) -> a) -> List b +build f = f Nil Cons + +@private +foldr :: (a -> b -> b) -> b -> List a -> b +foldr cons nil Nil = nil +foldr cons nil (Cons h t) = cons h (foldr cons nil t) + +@private +@inline +singleton :: a -> List a +singleton x = build (\nil cons -> cons x nil) + +@private +@inline +last :: List a -> a -> a +last l def = foldr (\x _ -> x) def l + +main = last (singleton "Hello") "Foo" +-- +Hello \ No newline at end of file