[Haskell-beginners] iterated function value sequence

Bob Ippolito bob at redivi.com
Sat Apr 5 15:55:01 UTC 2014


On Saturday, April 5, 2014, John M. Dlugosz <ngnr63q02 at sneakemail.com>
wrote:

> On 4/4/2014 3:35 PM, Bob Ippolito wrote:
>
>> There's a function named iterate in Prelude:
>>
>> λ> :info iterate
>> iterate :: (a -> a) -> a -> [a] -- Defined in `GHC.List'
>> λ> take 8 (iterate (\x -> 2 * x + 1) 0)
>> [0,1,3,7,15,31,63,127]
>>
>>  Nice.  I followed up with that to understand how it's written.
>
> Now, how might I do something like that but "forget" previous values to
> free up memory?
>

Garbage Collection does that for you. If all the references are gone, the
memory can be freed. If you have a specific use in mind I can show you what
that looks like.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140405/0079d6c3/attachment-0001.html>


More information about the Beginners mailing list