Proposal: Add strict iterate'

Edward Kmett ekmett at gmail.com
Wed Jul 30 14:56:57 UTC 2014


Likewise +1 for the idea, but no particular preference for implementation.


On Wed, Jul 30, 2014 at 8:39 AM, Jake McArthur <jake.mcarthur at gmail.com>
wrote:

> +1 for adding a strict version of iterate. I have to roll my own all the
> time. Regarding this particular implementation, I am neither for nor
> against, because I haven't thought it through yet.
> On Jul 29, 2014 8:48 PM, "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/20140730/22180230/attachment-0001.html>


More information about the Libraries mailing list