Proposal: Strict scanl, scanl1 and mapAccumL
Bas van Dijk
v.dijk.bas at gmail.com
Mon Nov 12 10:09:02 CET 2012
Hi,
Data.List exports strict versions of foldl an foldl1. I think it
should also export these strict versions of scanl, scanl1 and
mapAccumL:
scanl' :: (a -> b -> a) -> a -> [b] -> [a]
scanl' f q ls = q : (case ls of
[] -> []
x:xs -> let q' = f q x
in q' `seq` scanl f q' xs)
scanl1' :: (a -> a -> a) -> [a] -> [a]
scanl1' f (x:xs) = scanl' f x xs
scanl1' _ [] = []
mapAccumL' :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
mapAccumL' _ s [] = (s, [])
mapAccumL' f s (x:xs) = (s'',y:ys)
where
(s', y ) = f s x
(s'',ys) = s' `seq` mapAccumL' f s' xs
Is there a good reason they're not included?
Discussion deadline: 2 weeks (till Monday 26 November).
Regards,
Bas
More information about the Libraries
mailing list