Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Hashtbl.replace is incorrect according to its specification #5349
Original bug ID: 5349
The specification of Hashtbl.replace says "This is functionally equivalent to Hashtbl.remove tbl x followed by Hashtbl.add tbl x y."
That is not true if there is a binding [x'] of [tbl] such that [equal x x' = true] but [(x = x') = false] (with [equal] being the equality used for comparing keys of the table).
Steps to reproduce
Just compile and run the following program. If Hashtbl.replace correctly implements its specification, then the printed lines would be the same.
=== h.ml ===
module H =
let h = H.create 7
(* same implementation, but replacing H.replace by H.remove followed by H.add *)