Stack overflow in simple code with getStdRandom / randomR (GHC)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Stack overflow in simple code with getStdRandom / randomR (GHC)

Volker Stolz-3
The following three-liner creates a stack overflow (on my machine, MacOS), and I'm a bit puzzled as to why:

> import System.Random
>
> main = do
>  mapM (const (getStdRandom (randomR (0, 50000::Int)))) [0..10000000]

botanix:~ stolz$ ./a.out
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.

Yes, the list is quite long, but somehow I'd expected mapM to chug slowly along...printing "Hello World" doesn't create a stack overflow either, after all. My Haskell-foo has become a bit rusty, but I was wondering where I am missing a point or two here (and I couldn't find the correct profiler incantation that would give me more than a big black blob for the main-CAF). GHC is 6.12.3 on MacOS.

Cheers,
  Volker
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Stack overflow in simple code with getStdRandom / randomR (GHC)

Henning Thielemann

On Tue, 19 Apr 2011, Volker Stolz wrote:

> The following three-liner creates a stack overflow (on my machine, MacOS), and I'm a bit puzzled as to why:
>
>> import System.Random
>>
>> main = do
>>  mapM (const (getStdRandom (randomR (0, 50000::Int)))) [0..10000000]
>
> botanix:~ stolz$ ./a.out
> Stack space overflow: current size 8388608 bytes.
> Use `+RTS -Ksize -RTS' to increase it.

Shall it print something? I think mapM_ would be better here. If you
compile with 'ghc -Wall' then GHC will also warn you, that you ignored the
result of mapM. I think, HLint would also warn you.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Stack overflow in simple code with getStdRandom / randomR (GHC)

Volker Stolz-3
Blimey, I didn't notice that Krzysztof came to the same conclusion a bit earlier today, so I guess the answer is somewhere in his remark "One possible solution is to make cell holding std gen strict.". I'd still be interested in how to profile for this scenario, though.

  -Volker
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe