-
-
Save mimoo/3d40ce9fdd4ab687904633c43f9e7eb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(library | |
(name ocaml_bug) | |
(inline_tests) | |
(preprocess | |
(pps ppx_inline_test))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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