Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Demonstration of how non-tailcall warnings could work in F#
// This code demonstrates how the F# compiler could detect and emit a warning
// for non-tail-recursive calls to help avoid stack overflows.
// In response to:
module Blah
let foo x =
printfn "Foo: %x" x
let rec bar x =
match x with
| 0 ->
foo x // OK: non-tail-recursive call to a function which doesn't share the current stack frame (i.e., 'bar' or 'baz').
printfn "Zero"
| 1 ->
bar (x - 1) // Warning: this call is not tail-recursive
printfn "Uno"
baz x // OK: tail-recursive call.
| x ->
printfn "0x%08x" x
bar (x - 1) // OK: tail-recursive call.
and baz x =
printfn "Baz!"
bar (x - 1) // OK: tail-recursive call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.