Proposal: Add strict iterate'
Iavor Diatchki
iavor.diatchki at gmail.com
Wed Aug 6 19:59:23 UTC 2014
Hello,
I like the idea of using `headStrict` instead of adding another version of
`iterate`.
-Iavor
On Wed, Aug 6, 2014 at 10:46 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> Hi David,
>
> As suggested[1] by Takano Akio a few years ago iterate can be made strict
> by applying headStrict to its result:
>
> headStrict :: [a] -> [a]
> headStrict = foldr (\x y -> seq x (x : y)) []
>
> We might want to add this to Data.List unless there are no use-cases for a
> lazy accumulator in iterate in which case I'm +1 for a strict
> implementation.
>
> Bas
>
> [1] http://www.haskell.org/pipermail/libraries/2012-November/018775.html
> On 30 Jul 2014 02:48, "David Feuer" <david.feuer at gmail.com> wrote:
>
>> I think most if not all applications of iterate would prefer to
>> accumulate strictly—iterating a constant function is not very useful and
>> the spine of the result of iterate is always the same. Unlike unfoldr,
>> which has enough strictness built in to allow its caller to decide whether
>> to accumulate strictly, iterate is entirely lazy. I therefore propose:
>>
>> iterate' :: (a -> a) -> a -> [a]
>> iterate' f b = unfoldr go b
>> where
>> go x = x `seq` Just (x, f x)
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140806/82e5767a/attachment.html>
More information about the Libraries
mailing list