File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
(* * Some OCaml primitives for the extraction. *)
2
2
open Big_int
3
3
4
+ module Sum = struct
5
+ type ('a, 'b) t =
6
+ | Left of 'a
7
+ | Right of 'b
8
+
9
+ let destruct (s : ('a, 'b) t ) (c_x : 'a -> 'c ) (c_y : 'b -> 'c ) : 'c =
10
+ match s with
11
+ | Left x -> c_x x
12
+ | Right y -> c_y y
13
+ end
14
+
4
15
(* * Interface to the OCaml strings. *)
5
16
module String = struct
6
17
(* * Export an OCaml string. *)
24
35
let argv : string list =
25
36
Array. to_list Sys. argv
26
37
38
+ (* * Join. *)
39
+ let join (x : 'a Lwt.t ) (y : 'b Lwt.t ) : ('a * 'b) Lwt.t =
40
+ let r_x = ref None in
41
+ let r_y = ref None in
42
+ Lwt. bind (Lwt. join [
43
+ Lwt. bind x (fun x -> r_x := Some x; Lwt. return () );
44
+ Lwt. bind y (fun y -> r_y := Some y; Lwt. return () )])
45
+ (fun (_ : unit ) ->
46
+ match (! r_x, ! r_y) with
47
+ | (Some x , Some y ) -> Lwt. return (x, y)
48
+ | _ -> Lwt. fail_with " The join expected two answers." )
49
+
50
+ (* * First. *)
51
+ let first (x : 'a Lwt.t ) (y : 'b Lwt.t ) : ('a, 'b) Sum.t Lwt.t =
52
+ Lwt. choose [
53
+ Lwt. bind x (fun x -> Lwt. return @@ Sum. Left x);
54
+ Lwt. bind y (fun y -> Lwt. return @@ Sum. Right y)]
55
+
27
56
(* * List the files of a directory. *)
28
57
let list_files (directory : string ) : string list option Lwt.t =
29
58
Lwt. catch (fun _ ->
You can’t perform that action at this time.
0 commit comments