mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
removed the useless argument of Bij.BranchTo
This commit is contained in:
parent
fb04d0e1c5
commit
98ce2aa394
3 changed files with 11 additions and 11 deletions
4
bij.ml
4
bij.ml
|
|
@ -39,7 +39,7 @@ type _ t =
|
||||||
| Map : ('a -> 'b) * ('b -> 'a) * 'b t -> 'a t
|
| Map : ('a -> 'b) * ('b -> 'a) * 'b t -> 'a t
|
||||||
| Switch : ('a -> char * 'a inject_branch) * (char -> 'a extract_branch) -> 'a t
|
| Switch : ('a -> char * 'a inject_branch) * (char -> 'a extract_branch) -> 'a t
|
||||||
and _ inject_branch =
|
and _ inject_branch =
|
||||||
| BranchTo : 'b t * 'b * 'a -> 'a inject_branch
|
| BranchTo : 'b t * 'b -> 'a inject_branch
|
||||||
and _ extract_branch =
|
and _ extract_branch =
|
||||||
| BranchFrom : 'b t * ('b -> 'a) -> 'a extract_branch
|
| BranchFrom : 'b t * ('b -> 'a) -> 'a extract_branch
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ module SexpEncode(Sink : SINK) = struct
|
||||||
let y = inject x in
|
let y = inject x in
|
||||||
encode bij' y
|
encode bij' y
|
||||||
| Switch (inject, _), x ->
|
| Switch (inject, _), x ->
|
||||||
let c, BranchTo (bij', y, _) = inject x in
|
let c, BranchTo (bij', y) = inject x in
|
||||||
Sink.write_char sink c;
|
Sink.write_char sink c;
|
||||||
encode bij' y
|
encode bij' y
|
||||||
in encode bij x
|
in encode bij x
|
||||||
|
|
|
||||||
10
bij.mli
10
bij.mli
|
|
@ -44,16 +44,16 @@ val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
|
||||||
val map : inject:('a -> 'b) -> extract:('b -> 'a) -> 'b t -> 'a t
|
val map : inject:('a -> 'b) -> extract:('b -> 'a) -> 'b t -> 'a t
|
||||||
|
|
||||||
type _ inject_branch =
|
type _ inject_branch =
|
||||||
| BranchTo : 'b t * 'b * 'a -> 'a inject_branch
|
| BranchTo : 'b t * 'b -> 'a inject_branch
|
||||||
type _ extract_branch =
|
type _ extract_branch =
|
||||||
| BranchFrom : 'b t * ('b -> 'a) -> 'a extract_branch
|
| BranchFrom : 'b t * ('b -> 'a) -> 'a extract_branch
|
||||||
|
|
||||||
val switch : inject:('a -> char * 'a inject_branch) ->
|
val switch : inject:('a -> char * 'a inject_branch) ->
|
||||||
extract:(char -> 'a extract_branch) -> 'a t
|
extract:(char -> 'a extract_branch) -> 'a t
|
||||||
(** discriminates based on the next character.
|
(** Discriminates unions based on the next character.
|
||||||
The selection function, with type ['a -> char], is used to select a
|
[inject] is used to select a character, as well as mapping to another
|
||||||
bijection depending on the value.
|
type (the argument of the algebraic constructor);
|
||||||
' ' means "default" *)
|
[extract] retrieves which type to parse based on the character. *)
|
||||||
|
|
||||||
exception EOF
|
exception EOF
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ type term =
|
||||||
let bij_term =
|
let bij_term =
|
||||||
let rec mk_bij () =
|
let rec mk_bij () =
|
||||||
switch
|
switch
|
||||||
~inject:(fun t -> match t with
|
~inject:(function
|
||||||
| Const s -> 'c', BranchTo (string_, s, t)
|
| Const s -> 'c', BranchTo (string_, s)
|
||||||
| Int i -> 'i', BranchTo (int_, i, t)
|
| Int i -> 'i', BranchTo (int_, i)
|
||||||
| App l -> 'a', BranchTo (list_ (mk_bij ()), l, t))
|
| App l -> 'a', BranchTo (list_ (mk_bij ()), l))
|
||||||
~extract:(function
|
~extract:(function
|
||||||
| 'c' -> BranchFrom (string_, fun x -> Const x)
|
| 'c' -> BranchFrom (string_, fun x -> Const x)
|
||||||
| 'i' -> BranchFrom (int_, fun x -> Int x)
|
| 'i' -> BranchFrom (int_, fun x -> Int x)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue