I am trying delimcc hoping that I could implement dynamic binding, and I found something that is very likely to be a bug. I was reimplementing the code given in this paper : http://okmij.org/ftp/continuations/caml-shift-journal.pdf
open Delimcc
type ('k, 'v) tree = Empty | Node of ('k, 'v) tree * 'k * 'v * ('k, 'v) tree
let update: ('k, 'v) tree option prompt -> 'k -> ('v -> 'v)
-> ('k, 'v) tree -> ('k, 'v) tree =
fun pnf k f ->
let rec loop = function
Empty -> take_subcont pnf (fun _ () -> None)
| Node (l, k1, v1, r) ->
begin
match Stdlib.compare k k1 with
0 -> Node(l, k1, f v1, r)
| n when n < 0 -> Node(loop l, k1, v1, r)
| _ -> Node(l, k1, v1, loop r)
end in
loop
let t = Node(Node(Empty, 1, "truc", Node(Empty, 3, "machin", Empty)), 4, "fli", Empty)
let () = let pnf = new_prompt () in
match push_prompt pnf (fun () -> Some (update pnf 2 String.uppercase_ascii t)) with
Some _ -> print_endline "Successful update"
| None -> print_endline "Not Found"
This code prints Not Found as expected with an opam switch based on ocaml 4.08.0, but throws a Stack_overflow exception with ocaml 4.10.0. If I try to update the node 1 (a node already present in t) it prints Successful update as expected. I would gladly raise an issue but I am not sure where. Also is this library maintained or is it just a research work that is not supposed to be relied on ?
I installed delimcc with opam install delimcc and run the code with dune (dune exec ./minimal.exe).
Thanks