mapM as a Space Leak (Was: [Haskell-cafe] about Haskell code written to be "too smart")

roconnor at theorem.ca roconnor at theorem.ca
Thu Mar 26 15:04:40 EDT 2009


On Wed, 25 Mar 2009, Thomas Hartman wrote:

> With the state version, there's a lot of behind-the-scenes magic, and
> as we've seen, things can go wrong.
>
> Also, the issue isn't infinite lists, but lists that are longer than
> the sum of the partitions provided. The state monad partition version
> goes equally as badly awry if the test is restructured as
>
> testP pf = mapM_ putStrLn  [
>          show . pf ( take 1000 [3,7..] ) $ [1..10]
>          , show . pf [3,7,11,15] $ ( take (10^6) [1..])
>          , show . head . last $ pf (take 1000 $ [3,3..]) [1..10^6]
>        ]

This is interesting.  It seems to be the familiar issue that sequence does 
not play as nicely with the GC as one might imagine:
<http://www.reddit.com/r/haskell/comments/7itbi/mapm_mapm_and_monadic_statements/c06rwnb?context=1>

I suspect this may be a general problem that we will keep encountering 
when using higher-order functions, at least with this compiler.  I wonder 
if JHC or some other compiler might work better with these examples?

-- 
Russell O'Connor                                      <http://r6.ca/>
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''


More information about the Haskell-Cafe mailing list