]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Scanl.scl
Supply SVG text editor with element measurement context
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Scanl.scl
1 import "Prelude" hiding (scanl)
2
3 scanl :: (b -> a -> <e> b) -> b -> [a] -> <e> [b]
4 scanl f initial l = build (loop initial 0)
5   where
6     len = length l
7     loop cur i accum cons = let nl = cons accum cur
8                             in if i==len
9                                then nl
10                                else loop (f cur (l!i)) (i+1) nl cons
11                                
12 main = scanl (+) 0 [1,2,3]
13 --
14 [0, 1, 3, 6]