[Haskell-cafe] Comments and suggestions on code

Jonathan Cast jonathanccast at fastmail.fm
Sat Jan 12 13:11:43 EST 2008


On 12 Jan 2008, at 7:19 AM, Andre Nathan wrote:

> On Fri, 2008-01-11 at 19:14 -0800, Jonathan Cast wrote:
>> These are all known and expected.  As I said, you can expect lazy
>> versions to normally be slower than explicit loops.  The question is
>> whether 50% more time and 300% more memory has a higher cost in your
>> case than the extra complexity and reduced modularity of the lazy  
>> code.
>
> I think I understand... I expected the getDirectoryContents + mapM_ to
> have about the same memory usage of the readDirStream version, because
> getDirectoryContents would lazily give me one entry at a time, but the
> list of entries returned by it ends up being created anyway,

A nit: the list is almost certainly getting created lazily, or you'd  
get more than 300% more memory usage.  But you still get the list's  
cons cells as your bookkeeping baggage, and they take up space in  
exchange for greater flexibility.

> hence the
> larger memory usage, as the readDirStream version never builds a list.

jcc



More information about the Haskell-Cafe mailing list