Skip to content

Instantly share code, notes, and snippets.

@mimoo
Created March 6, 2022 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimoo/3d40ce9fdd4ab687904633c43f9e7eb3 to your computer and use it in GitHub Desktop.
Save mimoo/3d40ce9fdd4ab687904633c43f9e7eb3 to your computer and use it in GitHub Desktop.
(library
(name ocaml_bug)
(inline_tests)
(preprocess
(pps ppx_inline_test)))
module Oracle (SomeModule : Map.OrderedType) = struct
let counter = ref 0
module Map = Map.Make (SomeModule)
let memory : int Map.t ref = ref Map.empty
let to_bytes (t : SomeModule.t) : string =
match Map.find_opt t !memory with
| Some d -> string_of_int d
| None ->
incr counter;
memory := Map.add t !counter !memory;
string_of_int !counter
end
module A = struct
type t = { a : int; b : int } [@@deriving compare]
let to_bytes block =
let module Temp = Oracle (struct
type nonrec t = t
let compare = compare
end) in
Temp.to_bytes block
let%test_unit "to_bytes" =
let block = { a = 1; b = 2 } in
let b1 = to_bytes block in
let b2 = to_bytes block in
assert (b1 = "1");
assert (b1 = b2);
let other_block = { block with b = 3 } in
let b3 = to_bytes other_block in
assert (b3 = "2")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment