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