Created
September 24, 2012 13:44
-
-
Save hcarty/3776031 to your computer and use it in GitHub Desktop.
Bounded example
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 B = BatBounded | |
(* Integers between zero and 10, inclusive *) | |
module I10 = struct | |
type base_t = int | |
type t = int | |
let bounds = `c 0, `c 10 | |
let bounded ~bounds = B.saturate_of_ord ~bounds BatInt.ord | |
let base_of_t x = Some x | |
let base_of_t_exn = BatPervasives.identity | |
end | |
module SatI10 = struct | |
include B.Make(I10) | |
let ( +: ) a b = map2_exn ( + ) a b | |
let ( + ) a b = map_exn (( + ) b) a | |
end | |
(* | |
utop $ SatI10.(make 2 + 2 + 4);; | |
- : SatI10.t = 8 | |
utop $ SatI10.(make 2 + 2 + 9);; | |
- : SatI10.t = 10 | |
utop $ SatI10.(make 2 + 2 + ~-1);; | |
- : SatI10.t = 3 | |
utop $ SatI10.(make 2 + 2 +: make ~-1);; | |
- : SatI10.t = 4 | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment