[Haskell-cafe] Sub-optimal [code]

Daniel Fischer daniel.is.fischer at googlemail.com
Wed Feb 16 00:05:58 CET 2011


On Tuesday 15 February 2011 23:29:39, Andrew Coppin wrote:
> On 15/02/2011 08:35 PM, Daniel Fischer wrote:
> > The result is that the list
> >
> > [1 .. 10*1024*1024*k]
> >
> > from the penultimate line of random_file is shared between the four
> > iterations of the inner loop in file_batch (for k = 1 .. 4). Oops.
>
> Ouch! That's gotta sting in the morning... o_O

I think it has already stung, or we wouldn't have this thread, would we?

>
> I suppose what we could really do with is a combinator that runs a
> monadic action N times, without actually constructing a list N elements
> long in order to do so.

True enough. But I guess nobody¹ bothered yet because there are so many 
possible designs and most of them are trivial to implement in a line or two 
(so the pain of writing them repeatedly isn't bad enough).

¹ Not quite true, there's the monad-loops package on hackage which provides 
a handful of loops. But not the trivial nTimesDo.

> Then it becomes blatently obvious that there's
> nothing to share, and the problem goes away.
>
> They say that in Haskell, "a list *is* a loop". Apparently, not always.

No, not always. Some lists are just, you know, lists.




More information about the Haskell-Cafe mailing list