Created
September 7, 2016 21:14
-
-
Save smondet/aad54d4870688864b9c74b5b077cdbd6 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
module Abstract_value : | |
sig | |
type t | |
val create : unit -> t | |
end = | |
struct | |
type t = unit -> unit | |
let create () = | |
fun () -> () | |
end | |
type t = { | |
mutable abstract_value : Abstract_value.t; | |
(* Regular fields *) | |
x : int; | |
} | |
let make ~x = { | |
x; | |
abstract_value = Abstract_value.create (); | |
} | |
(* | |
The proper comparison function for this type, | |
which is incompatible with Pervasives.compare. | |
*) | |
let compare a b = | |
compare (abs a.x) (abs b.x) | |
let (=) a b = | |
compare a b = 0 | |
let (<>) a b = | |
compare a b <> 0 | |
let (<) a b = | |
compare a b < 0 | |
let (<=) a b = | |
compare a b <= 0 | |
let (>) a b = | |
compare a b > 0 | |
let (>=) a b = | |
compare a b >= 0 | |
(* | |
Make sure to run these tests with ocamlc, ocamlopt and any other OCaml | |
compiler you're using. | |
*) | |
let test_exception () = | |
try | |
ignore (Pervasives.compare (make ~x:0) (make ~x:0)); | |
false | |
with Invalid_argument "equal: functional value" -> | |
true | |
let () = | |
print_endline (if test_exception () then "Passed" else "Failed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like this?