]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Scanl.scl
Automatic execution of SCL tests in Maven
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Scanl.scl
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Scanl.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Scanl.scl
new file mode 100644 (file)
index 0000000..67821dd
--- /dev/null
@@ -0,0 +1,14 @@
+import "Prelude" hiding (scanl)\r
+\r
+scanl :: (b -> a -> <e> b) -> b -> [a] -> <e> [b]\r
+scanl f initial l = build (loop initial 0)\r
+  where\r
+    len = length l\r
+    loop cur i accum cons = let nl = cons accum cur\r
+                            in if i==len\r
+                               then nl\r
+                               else loop (f cur (l!i)) (i+1) nl cons\r
+                               \r
+main = scanl (+) 0 [1,2,3]\r
+--\r
+[0, 1, 3, 6]
\ No newline at end of file