Module TrampolineSource

Trampoline is a monad meant to help with "stack overflow" issues in js_of_ocaml programs.

JSOO does not have tail call optimization, so if you write a deeply recursive function, you may run into stack overflow issues.

If a function like:

  let some_function x =
    let rec f x =
      let a = f (x - 1) in
      let b = f (x - 2) in
      some_reduce a b
    in
    f x
  ;;

stack overflows, you can re-write it with trampoline with:

  let some_function x =
    let rec f x =
      let%bind.Trampoline a = f (x - 1) in
      let%bind.Trampoline b = f (x - 2) in
      Trampoline.return (some_reduce a b)
    in
    Trampoline.run (f x)
  ;;
Sourcetype 'a t
Sourceval lazy_ : 'a t Core.Lazy.t -> 'a t @@ portable
Sourceval run : 'a t -> 'a @@ portable
Sourceval return : 'a -> 'a t @@ portable
Sourceval all_map : ('k, 'v t, 'cmp) Core.Map.t -> ('k, 'v, 'cmp) Core.Map.t t @@ portable
Sourceval all : 'a t list -> 'a list t @@ portable
Sourceval map : 'a t -> f:('a -> 'b) -> 'b t @@ portable
Sourceval all_nonempty_list : 'a t Core.Nonempty_list.t -> 'a Core.Nonempty_list.t t @@ portable
Sourcemodule Let_syntax : sig ... end