I'm generating a list of random numbers:
let gen n =
let rec pom l n =
match n with
| 0 -> l
| _ ->
let el = Random.int 20000000
in pom (el::l) (n-1)
in
pom [] n
let lo = gen 1000000
What I get is
Fatal error: exception Stack_overflow
Why? I'm using tail recursion (and an accumulator)
EDIT:
You're right, the stack overflows on both sorts.
But if my code had a zillion lines, it would be a pain to debug it this way. I'd like to use ocamldebug here, just as a learning experience. I ran ocamldebug this way:
(ocd) r
Loading program... done.
Time: 88089944
Program end.
Uncaught exception: Stack_overflow
(ocd) b
Time: 88089943 - pc: 52 - module Pervasives
214 | hd :: tl -> <|b|>hd :: (tl @ l2)
(ocd) bt
#0 Pc: 52 Pervasives char 7700
#1 Pc: 64 Pervasives char 7715
#2 Pc: 64 Pervasives char 7715
#3 Pc: 64 Pervasives char 7715
#4 Pc: 64 Pervasives char 7715
#5 Pc: 64 Pervasives char 7715
#6 Pc: 64 Pervasives char 7715
// and so it goes on forever
This tells me nothing why my program has crashed. How could I debug it with ocamldebug?
(meta: should I post a separate thread for it or should I stay here)
List.sortfor correctness check