I have some code in F# that works fine under .net but overflows the stack under Mono. A related issue is that it seems to do so long before the stack space supposedly available to it runs out (it is started with System.Threading.Thread (ts, 1000000000)). As far as I can tell, the fold it dies in is tail-recursive and the stack trace looks as if tail-optimization is not being done. I am running 3.2.1 with --optimize=tailc.
Does somebody please know exactly what kinds of tail calls remove the calling stack and which do not? Or alternatively how to allocate more stack? Many thanks.
I am aware of Tailcall elimination in Mono
EDIT: here is an outline of the code as requested in the comments. It is a part of a fold over a large data structure, but the failing stacktrace has just mapk and myfold on it.
let rec myfold f x k =
let rec mapk xs k =
match xs with
[] -> k []
| x::xs -> mapk xs (fun xs' -> myfold f x (fun x' -> (x' :: xs') |> k))
...
mapk (...) ( ... >> k)
As far as I know, --optimize=tailc
isn't a supported F# compiler flag.
I don't think there's a way to enable/disable tailcall-optimization support in Mono (from the command-line, anyway); the F# compiler flag to enable tail-call optimizations is --tailcalls+
, but according to Compiler Options (F#) that's on by default.
I think your best choices to get this resolved are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With