Skip to content

Commit 3c6117e

Browse files
committed
1 parent c110000 commit 3c6117e

File tree

6 files changed

+106
-12
lines changed

6 files changed

+106
-12
lines changed

serlib/serType.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module type SJHC1 = sig
2424
type 'a t [@@deriving sexp,yojson,hash,compare]
2525
end
2626

27+
module type SJHC2 = sig
28+
type ('a, 'b) t [@@deriving sexp,yojson,hash,compare]
29+
end
30+
2731
(* Bijection with serializable types *)
2832
module type Bijectable = sig
2933

@@ -85,6 +89,34 @@ module Biject1(M : Bijectable1) : SJHC1 with type 'a t = 'a M.t = struct
8589
let compare f x1 x2 = M.compare__t f (M.of_t x1) (M.of_t x2)
8690
end
8791

92+
module type Bijectable2 = sig
93+
94+
(* Base Type *)
95+
type ('a, 'b) t
96+
97+
(* Representation type *)
98+
type ('a, 'b) _t [@@deriving sexp,yojson,hash,compare]
99+
100+
(* Need to be bijetive *)
101+
val to_t : ('a, 'b) _t -> ('a, 'b) t
102+
val of_t : ('a, 'b) t -> ('a, 'b) _t
103+
end
104+
105+
module Biject2(M : Bijectable2) : SJHC2 with type ('a, 'b) t = ('a, 'b) M.t = struct
106+
107+
type ('a, 'b) t = ('a, 'b) M.t
108+
109+
let sexp_of_t f g x = M.sexp_of__t f g (M.of_t x)
110+
let t_of_sexp f g s = M.to_t (M._t_of_sexp f g s)
111+
112+
let to_yojson f g p = M._t_to_yojson f g (M.of_t p)
113+
let of_yojson f g p = M._t_of_yojson f g p |> Result.map M.to_t
114+
115+
let hash_fold_t f g st x = M.hash_fold__t f g st (M.of_t x)
116+
117+
let compare f g x1 x2 = M.compare__t f g (M.of_t x1) (M.of_t x2)
118+
end
119+
88120
(* We do our own alias as to have better control *)
89121
let _sercast = Obj.magic
90122

serlib/serType.mli

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ module type SJHC1 = sig
2828

2929
end
3030

31+
module type SJHC2 = sig
32+
33+
type ('a, 'b) t [@@deriving sexp,yojson,hash,compare]
34+
35+
end
36+
3137
(** Bijection with serializable types *)
3238
module type Bijectable = sig
3339

@@ -62,6 +68,22 @@ end
6268

6369
module Biject1(M : Bijectable1) : SJHC1 with type 'a t = 'a M.t
6470

71+
module type Bijectable2 = sig
72+
73+
(* Base Type *)
74+
type ('a, 'b) t
75+
76+
(* Representation type *)
77+
type ('a, 'b) _t [@@deriving sexp,yojson,hash,compare]
78+
79+
(* Need to be bijetive *)
80+
val to_t : ('a, 'b) _t -> ('a, 'b) t
81+
val of_t : ('a, 'b) t -> ('a, 'b) _t
82+
end
83+
84+
module Biject2(M : Bijectable2) : SJHC2 with type ('a, 'b) t = ('a, 'b) M.t
85+
86+
6587
module type Pierceable = sig
6688

6789
(** Type to pierce *)

serlib/ser_declarations.ml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,19 @@ let sexp_of_constant_body e =
125125
(* We cannot handle VM values *)
126126
sexp_of_constant_body { e with const_body_code = None }
127127

128+
(*
129+
module Retroknowledge =
130+
struct
128131
module MRK = struct
129-
type 'a t = 'a Declarations.module_retroknowledge
130-
let name = "Declarations.module_retroknowledge"
132+
type t = Retroknowledge.action
133+
let name = "Retroknowledge.action"
131134
end
132135
133-
module B_ = SerType.Opaque1(MRK)
134-
type 'a module_retroknowledge = 'a B_.t
135-
[@@deriving sexp,yojson,hash,compare]
136+
module B_ = SerType.Opaque(MRK)
137+
type action = B_.t
138+
[@@deriving sexp,yojson,hash,compare]
139+
end
140+
*)
136141

137142
type recursivity_kind =
138143
[%import: Declarations.recursivity_kind]
@@ -188,6 +193,34 @@ type 'a with_declaration =
188193
[%import: 'a Declarations.with_declaration]
189194
[@@deriving sexp,yojson,hash,compare]
190195

196+
type mod_body =
197+
[%import: Declarations.mod_body]
198+
[@@deriving sexp,yojson,hash,compare]
199+
200+
type mod_type =
201+
[%import: Declarations.mod_type]
202+
[@@deriving sexp,yojson,hash,compare]
203+
204+
module WMBBiject = struct
205+
type ('a, 'b) t = ('a, 'b) Declarations.when_mod_body
206+
207+
type ('a, 'b) _t = 'b option
208+
[@@deriving sexp,yojson,hash,compare]
209+
210+
let to_t (type a b) (x : b option) : (a, b) Declarations.when_mod_body = match x with
211+
| Some x -> Obj.magic @@ Declarations.ModBodyVal x
212+
| None -> Obj.magic @@ Declarations.ModTypeNul
213+
214+
let of_t (type a) (type b) (x : (a, b) Declarations.when_mod_body) : b option = match x with
215+
| Declarations.ModBodyVal x -> Some x
216+
| Declarations.ModTypeNul -> None
217+
end
218+
219+
module WMB = SerType.Biject2(WMBBiject)
220+
221+
type ('a, 'b) when_mod_body = ('a, 'b) WMB.t
222+
[@@deriving sexp,yojson,hash,compare]
223+
191224
type 'a module_alg_expr =
192225
[%import: 'a Declarations.module_alg_expr]
193226
[@@deriving sexp,yojson,hash,compare]

serlib/ser_declarations.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ type mutual_inductive_body = Declarations.mutual_inductive_body
9494
type rewrite_rule = Declarations.rewrite_rule
9595
[@@deriving sexp,yojson,hash,compare]
9696

97+
type mod_body = Declarations.mod_body
98+
type mod_type = Declarations.mod_type
99+
100+
type ('a, 'v) when_mod_body = ('a, 'v) Declarations.when_mod_body
101+
[@@deriving sexp,yojson,hash,compare]
102+
97103
type 'a module_alg_expr = 'a Declarations.module_alg_expr
98104
[@@deriving sexp,yojson,hash,compare]
99105

serlib/ser_retroknowledge.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ let retroknowledge_of_sexp = Serlib_base.opaque_of_sexp ~typ:"Retroknowledge.ret
2525
(* type entry =
2626
* [%import: Retroknowledge.entry] *)
2727

28-
type action =
29-
[%import: Retroknowledge.action]
28+
module MRK = struct
29+
type t = Retroknowledge.action
30+
let name = "Retroknowledge.action"
31+
end
3032

31-
let sexp_of_action = Serlib_base.sexp_of_opaque ~typ:"Retroknowledge.action"
32-
let action_of_sexp = Serlib_base.opaque_of_sexp ~typ:"Retroknowledge.action"
33+
module B_ = SerType.Opaque(MRK)
34+
type action = B_.t
35+
[@@deriving sexp,yojson,hash,compare]

serlib/ser_retroknowledge.mli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ val sexp_of_retroknowledge : retroknowledge -> Sexp.t
2424
val retroknowledge_of_sexp : Sexp.t -> retroknowledge
2525

2626
type action = Retroknowledge.action
27-
28-
val sexp_of_action : action -> Sexp.t
29-
val action_of_sexp : Sexp.t -> action
27+
[@@deriving sexp,yojson,hash,compare]

0 commit comments

Comments
 (0)