simple program crash (GHC 5.02, Hugs)

matthew_bentham@yahoo.com matthew_bentham@yahoo.com
Fri, 21 Dec 2001 22:43:21 +0000 (GMT)


Oleg Galbert wrote:
> I'm a newbie in Haskell.
> I tryed to compare performance of GHC compiled code and Ocaml compiled 
> code
> on a small example:
>
> test n cosx
>         | n==0 = cosx
>         | otherwise = test (n-1) (cosx+cos(cosx))
>
> main = print ( test  10000000 0.0 )
>
> I compiled it on Win NT :
>
> ghc -o test_haskell.exe test_haskell.hs
>
<snip>
> Does a stack usage depends on number of recursive calls? Is there a tail
> recursion optimization?
<snip>

Yes and yes.  To turn on the optimiser, add -O or -O2 to the compiler
command line:

[mjb67@mjb67 mjb67]$ ghc -o test_haskell test_haskell.hs
[mjb67@mjb67 mjb67]$ ./test_haskell
Stack space overflow: current size 1048576 bytes.
Use `+RTS -Ksize' to increase it.
[mjb67@mjb67 mjb67]$ ghc -O2 -o test_haskell test_haskell.hs
[mjb67@mjb67 mjb67]$ ./test_haskell
1.5707963267948966
[mjb67@mjb67 mjb67]$

Hope this helps,

Matthew (fellow Haskell newbie :-) )