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
open Batteries | |
module type Level_sig = sig | |
type t | |
val to_string : t -> string | |
val default_level : t | |
val compare : t -> t -> int | |
end | |
module type S = sig |
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 Lwt_socket = struct | |
type 'a t = { | |
socket : 'a ZMQ.Socket.t; | |
fd : Lwt_unix.file_descr; | |
} | |
let of_socket socket = { | |
socket; | |
fd = Lwt_unix.of_unix_file_descr ~blocking:false (ZMQ.Socket.get_fd socket); | |
} |
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 O = BatOrd | |
type 'a bounding_f = min:'a -> max:'a -> 'a -> 'a option | |
let bounding_of_ord ?default_low ?default_high ord = | |
fun ~min ~max -> assert (ord min max != O.Gt); | |
fun x -> | |
match ord x min, ord x max with | |
| O.Lt, _ -> default_low | |
| _, O.Gt -> default_high |
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
let unique (type s) ?(cmp = compare) (l : s list) = | |
let module M = struct | |
type t = s | |
let compare = cmp | |
end in | |
let module S = Set.Make(M) in | |
let s = List.fold_left (fun accu x -> S.add x accu) S.empty l in | |
S.elements s |
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
(* | |
Very WIP, assuming it goes anywhere. | |
Requires: | |
- Batteries | |
- Ulib (The stdlib extension, not the Unicode library - see oasis-db) | |
- gsl-ocaml | |
Compile with: ocamlbuild -use-ocamlfind -pkgs gsl,ulib,batteries odl.cma | |
*) |
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
let saturate_of_ord ~(bounds : 'a bound_t * 'a bound_t) ord = | |
match bounds with | |
| `o l, `o h | |
| `c l, `c h | |
| `o l, `c h | |
| `c l, `o h -> | |
bounding_of_ord ~default_low:l ~default_high:h ord ~bounds | |
|- BatOption.get | |
| `u, `o h | |
| `u, `c h -> |
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
(* Experimenting with different ideas for convenience additions to BatBounded *) | |
module type S = sig | |
type base_t | |
type t | |
val make : base_t -> t | |
val bind : (base_t -> t) -> t -> t | |
val map2 : (base_t -> base_t -> base_t) -> t -> t -> t | |
end |
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 |
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
let pp_enum ?(flush = false) ?(first = "") ?(last = "") ?(sep = " ") ?(indent = String.length first) pp f e = | |
let open Format in | |
pp_open_box f indent; | |
pp_print_cut f (); | |
pp_print_string f first; | |
pp_print_cut f (); | |
match Enum.get e with | |
| None -> | |
pp_print_string f last; | |
pp_close_box f (); |
OlderNewer