scans.hs
#496
- Author
- winny
- Created
- June 2, 2022, 2:41 p.m.
- Expires
- Never
- Size
- 292 bytes
- Hits
- 136
- Syntax
- Haskell
- Private
- ✗ No
scanl :: (b -> a -> b) -> b -> [a] -> [b]
scanl f b = g [b] b
where g xs x [] = reverse xs
g xs x (y:ys) = g (x':xs) x' ys
where x' = x `f` y
scanl' :: (b -> a -> b) -> b -> [a] -> [b]
scanl' f b as = reverse $ foldl g [b] as
where g (x:xs) y = (x `f` y):x:xs