module Pattern_syntax: sig
.. end
general functions about patterns
general functions about patterns
Destructors and selector functions
val is_var_wild_pat : Typed_ast.pat -> bool
is_var_wild_pat p
checks whether the pattern p
is
a wildcard or a variable pattern. Before checking
type-annotations, parenthesis, etc. are removed.
val is_var_pat : Typed_ast.pat -> bool
is_var_pat p
checks whether the pattern p
is
a variable pattern.
val is_ext_var_pat : Typed_ast.pat -> bool
is_ext_var_pat p
checks whether the pattern p
is
a variable pattern in the broadest sense. In contrast
to is_var_pat p
also variables with type-annotations and
parenthesis are accepted. is_var_wild_pat p
additionally
accepts wildcard patterns.
val is_var_tup_pat : Typed_ast.pat -> bool
is_var_tup_pat p
checks whether the pattern p
consists only
of variable and tuple patterns.
val is_var_wild_tup_pat : Typed_ast.pat -> bool
is_var_wild_tup_pat p
checks whether the pattern p
consists only
of variable, wildcard and tuple patterns.
val dest_var_pat : Typed_ast.pat -> Name.t option
dest_var_pat p
destructs variable patterns and returs their name. If p
is not a variable pattern, None
is returned.
val dest_ext_var_pat : Typed_ast.pat -> Name.t option
dest_ext_var_pat p
is an extended version of det_var_pat p
. In addition
to det_var_pat p
it can handle variable patterns with type annotations and
is able to strip parenthesis.
val pat_to_ext_name : Typed_ast.pat -> Typed_ast.name_lskips_annot option
pat_to_ext_name p
is very similar to dest_ext_var_pat p
.
However, intead of returning just a name, pat_to_ext_name
returns additionally
the whitespace and the type in form of a name_lskips_annot
.
val is_wild_pat : Typed_ast.pat -> bool
is_wild_pat p
checks whether the pattern p
is
a wildcard pattern.
val dest_tup_pat : int option -> Typed_ast.pat -> Typed_ast.pat list option
dest_tup_pat lo p
destructs a tuple pattern. If
p
is no tuple pattern, None
is returned. Otherwise,
it destructs the tuple pattern into a list of patterns pL
.
If lo
is not None
, it checks whether the length of this
list matches the length given by lo
. If this is the case
Some pL
is returned, otherwise None
.
val mk_tup_pat : Typed_ast.pat list -> Typed_ast.pat
mk_tup_pat [p1, ..., pn]
creates the pattern (p1, ..., pn)
.
val is_tup_pat : int option -> Typed_ast.pat -> bool
is_tup_pat lo p
checks whether p
is a tuple pattern of the given length.
see dest_tup_pat
val dest_tf_pat : Typed_ast.pat -> bool option
dest_tf_pat p
destructs boolean literal patterns,
i.e. true
and false
patterns.
val is_tf_pat : Typed_ast.pat -> bool
if_tf_pat p
checks whether p
is the true
or false
pattern.
val is_t_pat : Typed_ast.pat -> bool
if_t_pat p
checks whether p
is the true
pattern.
val is_f_pat : Typed_ast.pat -> bool
if_f_pat p
checks whether p
is the false
pattern.
val mk_tf_pat : bool -> Typed_ast.pat
mk_tf_pat b
creates true
or false
pattern.
val mk_paren_pat : Typed_ast.pat -> Typed_ast.pat
adds parenthesis around a pattern
val mk_opt_paren_pat : Typed_ast.pat -> Typed_ast.pat
adds parenthesis around a pattern, when needed
val dest_num_pat : Typed_ast.pat -> int option
dest_num_pat p
destructs number literal patterns
val is_num_pat : Typed_ast.pat -> bool
is_num_pat p
checks whether p
is a number pattern.
val mk_num_pat : Types.t -> int -> Typed_ast.pat
mk_num_pat num_ty i
makes a number pattern.
val dest_num_add_pat : Typed_ast.pat -> (Name.t * int) option
dest_num_add_pat p
destructs number addition literal patterns
val mk_num_add_pat : Types.t -> Name.t -> int -> Typed_ast.pat
mk_num_add_pat num_ty i
makes a number addition pattern.
val is_num_add_pat : Typed_ast.pat -> bool
is_num_add_pat p
checks whether p
is a number addition pattern.
val num_ty_pat_cases : (Name.t -> 'a) ->
(int -> 'a) ->
(Name.t -> int -> 'a) -> 'a -> (Typed_ast.pat -> 'a) -> Typed_ast.pat -> 'a
num_ty_pat_cases f_v f_i f_a f_w f_else p
performs case analysis for patterns of type num. Depending of which form the pattern
p
has,
different argument functions are called:
- v -> f_v v
- c (num constant) -> f_i i
- v + 0 -> f_v v
- v + i (for i > 0) -> f_a v i
- _ -> f_w
- p (everything else) -> f_else p
val dest_string_pat : Typed_ast.pat -> string option
dest_string_pat p
destructs number literal patterns
val is_string_pat : Typed_ast.pat -> bool
is_string_pat p
checks whether p
is a number pattern.
val dest_cons_pat : Typed_ast.pat -> (Typed_ast.pat * Typed_ast.pat) option
dest_cons_pat p
destructs list-cons patterns.
val is_cons_pat : Typed_ast.pat -> bool
val dest_list_pat : int option -> Typed_ast.pat -> Typed_ast.pat list option
dest_list_pat p
destructs list patterns.
val is_list_pat : int option -> Typed_ast.pat -> bool
val dest_const_pat : Typed_ast.pat ->
(Typed_ast.const_descr_ref Types.id * Typed_ast.pat list) option
dest_contr_pat p
destructs constructor patterns.
val is_const_pat : Typed_ast.pat -> bool
val dest_record_pat : Typed_ast.pat ->
(Typed_ast.const_descr_ref Types.id * Typed_ast.pat) list option
dest_record_pat p
destructs record patterns.
val is_record_pat : Typed_ast.pat -> bool
Classification of Patterns
val is_constructor : Ast.l -> Typed_ast.env -> Target.target -> Typed_ast.const_descr_ref -> bool
is_constructor l env targ c
checks whether c
is a constructor
for target targ
in environment env
. If you want to know
whether it is for any target, use the identity target.
Internally, it checks whether type_defs_get_constr_families
returns a non-empty list.
val is_buildin_constructor : Ast.l -> Typed_ast.env -> Target.target -> Typed_ast.const_descr_ref -> bool
is_buildin_constructor l env targ c
checks whether c
is a
build-in constructor for target targ
in environment env
. Build-in
constructors are constructors, which the target pattern
compilation can handle.
val is_not_buildin_constructor : Ast.l -> Typed_ast.env -> Target.target -> Typed_ast.const_descr_ref -> bool
is_not_buildin_constructor l env targ c
checks whether c
is a
constructor for target targ
in environment env
, but not a build-in one. Not build-in
constructors get compiled away during pattern compilation.
val direct_subpats : Typed_ast.pat -> Typed_ast.pat list
direct_subpats p
returns a list of all the direct subpatterns of p
.
val subpats : Typed_ast.pat -> Typed_ast.pat list
subpats p
returns a list of all the subpatterns of p
.
In contrast to direct_subpats p
really all subpatterns are
returned, not only direct ones. This means that the result of
direct_subpats p
is a subset of subpats p
.
val exists_subpat : (Typed_ast.pat -> bool) -> Typed_ast.pat -> bool
exists_pat cf p
checks whether p
has a subpattern p'
such that cf p'
holds.
val for_all_subpat : (Typed_ast.pat -> bool) -> Typed_ast.pat -> bool
for_all_subpat cf p
checks whether all subpatterns p'
of p
satisfy cf p'
.
val single_pat_exhaustive : Typed_ast.pat -> bool
single_pat_exhaustive p
checks whether the pattern p
is exhaustive.
val pat_vars_src : Typed_ast.pat -> (Name.lskips_t, unit) Types.annot list
pat_vars_src p
returns a list of all the variable names occuring in the pattern.
The names are annotated with the type and the whitespace information.
miscellaneous
: Typed_ast.pat -> Ast.lex_skips
pat_extract_lskips p
extracts all whitespace from a pattern
val split_var_annot_pat : Typed_ast.pat -> Typed_ast.pat
split_var_annot_pat p
splits annotated variable patterns in variable patterns + type annotation.
All other patterns are returned unchanged.
exception Pat_to_exp_unsupported of Ast.l * string
val pat_to_exp : Typed_ast.env -> Typed_ast.pat -> Typed_ast.exp
pat_to_exp env p
tries to convert p
into a corresponding expression. This might fail,
e.g. if p
contains wildcard patterns. If it fails a pat_to_exp_unsupported
exception is raised.