Re: [Haskell-cafe] Sub-optimal [code]

2011-02-20 Thread Andrew Coppin
On 16/02/2011 11:09 PM, Max Bolingbroke wrote: Thinking about it some more, this example is actually quite interesting because if you *prevent* the list from being floated the forM gets foldr/build fused into a totally listless optimal loop. It really does seem like a shame to disable that

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread James Andrew Cook
On Feb 15, 2011, at 6:05 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Tuesday 15 February 2011 23:29:39, Andrew Coppin wrote: Ouch! 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

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread Daniel Fischer
On Wednesday 16 February 2011 19:31:05, James Andrew Cook wrote: Doesn't Control.Monad.replicateM_ do exactly that? Yes, right, forgot about that. That would've worked fine in Andrew's case. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread Andrew Coppin
On 16/02/2011 06:31 PM, James Andrew Cook wrote: Doesn't Control.Monad.replicateM_ do exactly that? 10 points to Gryffindore. (Now, if only there was a version that feeds an integer to the monadic action as well... Still, it's not hard to implement.)

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread Max Bolingbroke
On 16 February 2011 21:51, Andrew Coppin andrewcop...@btinternet.com wrote: (Now, if only there was a version that feeds an integer to the monadic action as well... Still, it's not hard to implement.) As simple as: forM [1..x] mk_my_action ___

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread Daniel Fischer
On Wednesday 16 February 2011 23:13:10, Max Bolingbroke wrote: On 16 February 2011 21:51, Andrew Coppin andrewcop...@btinternet.com wrote: (Now, if only there was a version that feeds an integer to the monadic action as well... Still, it's not hard to implement.) As simple as: forM

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-16 Thread Max Bolingbroke
On 16 February 2011 22:48, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: The problem with that is that under certain circumstances the list is shared in nested loops, which was what caused the thread (it was mapM_ and not forM_, but I'd be very surprised if they behaved differently

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Andrew Coppin
I tried -O2 -fno-cse. No difference. I also tried -O2 -fno-full-laziness. BIG DIFFERENCE. See also the very old GHC ticket at http://hackage.haskell.org/trac/ghc/ticket/917 I don't know if that's the problem or not, but it might plausibly be. Here's the smallest version of the program that

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Daniel Fischer
On Tuesday 15 February 2011 20:15:54, Andrew Coppin wrote: I tried -O2 -fno-cse. No difference. I also tried -O2 -fno-full-laziness. BIG DIFFERENCE. See also the very old GHC ticket at http://hackage.haskell.org/trac/ghc/ticket/917 I don't know if that's the problem or not, but it

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Claude Heiland-Allen
On 15/02/11 20:35, Daniel Fischer wrote: Which makes me wonder: unwanted sharing of lists [1 .. n] or similar is a frequent cause of space leaks, so would it be possible to teach GHC to not share such lists (unless they're bound to a name to indicate sharing is wanted)? In particular for

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Daniel Fischer
On Tuesday 15 February 2011 22:20:06, Claude Heiland-Allen wrote: Compare with the heap profile graph output from this short program which uses a horrible data-dependency hack to force recomputation: main = do print $ length [(x,y) | x - [(1 :: Int) .. 1], y - [(1 :: Int) ..

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Andrew Coppin
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 suppose

Re: [Haskell-cafe] Sub-optimal [code]

2011-02-15 Thread Daniel Fischer
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).

Re: [Haskell-cafe] Sub-optimal

2011-02-14 Thread Andrew Coppin
Is this a known bug? (GHC 6.10.x) It's known to happen when optimising shares what shouldn't be shared. Try compiling with -O2 -fno-cse (if that doesn't help, it doesn't necessarily mean it's not unwanted sharing, though). And, please, let us see some code to identify the problem. I tried -O2

Re: [Haskell-cafe] Sub-optimal

2011-02-14 Thread Max Bolingbroke
On 14 February 2011 21:00, Andrew Coppin andrewcop...@btinternet.com wrote: Is this a known bug? (GHC 6.10.x) It's known to happen when optimising shares what shouldn't be shared. Try compiling with -O2 -fno-cse (if that doesn't help, it doesn't necessarily mean it's not unwanted sharing,

Re: [Haskell-cafe] Sub-optimal

2011-02-13 Thread Maciej Wos
I was battling a similar (the same?) issue recently. The problem might indeed be caused by excessive sharing. There's a good example in GHC's trac [1]. Try compiling your code with -O2 and -fno-full-laziness. There is also an issue with full-laziness and recursive overloaded functions [2]. Again,

[Haskell-cafe] Sub-optimal

2011-02-12 Thread Andrew Coppin
I have a small program that fills a file with random numbers. If I compile it without optimisation, it runs in constant space. And yet, if I supply -O2 (or even just -O1), for large output files the program gobbles large amounts of RAM. Is this a known bug? (GHC 6.10.x)

Re: [Haskell-cafe] Sub-optimal

2011-02-12 Thread Daniel Fischer
On Saturday 12 February 2011 11:30:26, Andrew Coppin wrote: I have a small program that fills a file with random numbers. If I compile it without optimisation, it runs in constant space. And yet, if I supply -O2 (or even just -O1), for large output files the program gobbles large amounts of