Dear Alastair,

while playing around with the stack size the following error croped
up:

Prelude> foldl (\n _ -> n + 1) 0 [1..1000]
1000
Prelude> foldl (\n _ -> n + 1) 0 [1..10000]

ERROR: Control stack overflow
Prelude> foldl (\n _ -> n + 1) 0 [1..100000]
Segmentation fault (core dumped)


BTW it would be truely wonderful if Hugs provided a way to increase the
stack size using a command line option. [We use Haskell for the
first-year course on computing science. For the lessons on asymptotic
complexity it is nice to let the students _experience_ the quadratic
running time of insertion sort.

> insertionSort                 :: (Ord a) => [a] -> [a]
> insertionSort []              =  []
> insertionSort (a : as)        =  insert a (insertionSort as)
>
> insert                        :: (Ord a) => a -> [a] -> [a]
> insert a []                   =  [a]
> insert a (a' : as)
>     | a <= a'                 =  a  : a' : as
>     | otherwise               =  a' : insert a as

However, a list containing 1000 elements is sorted to fast, and for
10000 elements we have a control stack overflow.

Main> sum (insertionSort [1000,999 .. 1])
500500
Main> sum (insertionSort [10000,9999 .. 1])

ERROR: Control stack overflow]

It would be even more wonderful if the sizes of the various areas
(heap, stack etc.) would adopt to the programs needs. But this is
probably asking to match.

Cheers, Ralf

PS: Im using Version 971118 on

blei 57> uname -a
SunOS blei 5.6 Generic sun4u sparc SUNW,Ultra-1

Reply via email to