Proposal: Strict scanl, scanl1 and mapAccumL

Bas van Dijk v.dijk.bas at gmail.com
Mon Nov 12 11:34:35 CET 2012


I just realized that mapAccumL' is not needed since the caller has the
ability to force the accumlator. So please ignore that part of my
proposal. This leaves just scanl' and scanl1' as orignally proposed by
Niklas Hambüchen.

On 12 November 2012 10:09, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> 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