Fixed.S2
Nested fixed-point type where an element of the Pattern
is itself a fixed-point type. We use this to represent statements which contain expressions.
module Pattern : Pattern.S2
val fold : ('c -> 'a -> 'c) -> ('c -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c
include Ppx_compare_lib.Comparable.S2 with type ('a, 'b) t := ('a, 'b) t
val compare :
'a Base__Ppx_compare_lib.compare ->
'b Base__Ppx_compare_lib.compare ->
('a, 'b) t Base__Ppx_compare_lib.compare
include Ppx_hash_lib.Hashable.S2 with type ('a, 'b) t := ('a, 'b) t
val hash_fold_t :
'a Base__Ppx_hash_lib.hash_fold ->
'b Base__Ppx_hash_lib.hash_fold ->
('a, 'b) t Base__Ppx_hash_lib.hash_fold
include Foldable.S2 with type ('a, 'b) t := ('a, 'b) t
val fold_left :
f:('c -> 'a -> 'c) ->
g:('c -> 'b -> 'c) ->
init:'c ->
('a, 'b) t ->
'c
val fold_right :
f:('a -> 'c -> 'c) ->
g:('b -> 'c -> 'c) ->
init:'c ->
('a, 'b) t ->
'c
val any :
pred_first:('a -> bool) ->
pred_second:('b -> bool) ->
?init:bool ->
('a, 'b) t ->
bool
val all :
pred_first:('a -> bool) ->
pred_second:('b -> bool) ->
?init:bool ->
('a, 'b) t ->
bool
val fold_pattern :
f:(('a * 'r1 First.Pattern.t) -> 'r1) ->
g:(('b * ('r1, 'r2) Pattern.t) -> 'r2) ->
('a, 'b) t ->
'r2
fold_pattern
traverses the data structure from the bottom up replacing the original meta data of First
with type 'a
with some result type 'r1
and the meta data at this level withtype 'b
to another result type 'r2
and combines the result values on the way back up.
val rewrite_bottom_up :
f:('a First.t -> 'a First.t) ->
g:(('a, 'b) t -> ('a, 'b) t) ->
('a, 'b) t ->
('a, 'b) t
rewrite_bottom_up
specializes fold_pattern
so that the result type 'r1
is equal to the type of the nested fixed-point type i.e. 'r1 = 'a First.t
and the result type 'r2
is equal to the top-level fixed-point type i.e. 'r2 = ('a,'b) t
.
This also means that the function f
can be written with our nested fixed-point type 'a First.t
as its argument and g
can be written with ('a,'b) t
as its argument.
val unfold_pattern :
f:('r1 -> 'a * 'r1 First.Pattern.t) ->
g:('r2 -> 'b * ('r1, 'r2) Pattern.t) ->
'r2 ->
('a, 'b) t
unfold_pattern
takes a seed value of type 'r2
and uses the function g
to generate a tuple of meta-data and a pattern with types 'r1
and 'r2
. The functions proceeds by recursively applying g
to the contained values of type 'r2
and f
to values of type 'r1
finishing when the pattern contains no values of type 'r1
or 'r2
.