Debian Codegraph @

expander/renaming.mli

raw symbols SCIP
1 (* A renaming is a mapping from type variable name to type variable name.
2 In definitions such as:
3
4 type 'a t =
5 | A : <type> -> 'b t
6 | B of 'a
7
8 we generate a function that takes an sexp_of parameter named after 'a, but 'a is not in
9 scope in <type> when handling the constructor A (because A is a gadt constructor).
10 Instead the type variables in scope are the ones defined in the return type of A,
11 namely 'b. There could be less or more type variable in cases such as:
12
13 type _ less = Less : int less
14 type _ more = More : ('a * 'a) more
15
16 If for instance, <type> is ['b * 'c], when we find 'b, we will look for ['b] in the
17 renaming and find ['a] (only in that gadt branch, it could be something else in other
18 branches), at which point we can call the previously bound sexp_of parameter named
19 after 'a.
20 If we can't find a resulting name, like when looking up ['c] in the renaming, then we
21 assume the variable is existentially quantified and treat it as [_] (which is ok,
22 assuming there are no constraints). *)
23 open! Base
24 open! Ppxlib
25
26 type t
27
28 (** Renaming for contexts outside a type declaration, such as expression extensions. *)
29 val without_type : unit -> t
30
31 (** Renaming for a type declaration. Adds [prefix] to bindings for type parameters. *)
32 val of_type_declaration : type_declaration -> prefix:string -> t
33
34 (** Adds a new name with the given [prefix] for a universally bound type variable. *)
35 val add_universally_bound : t -> string loc -> prefix:string -> t
36
37 module Binding_kind : sig
38 type t =
39 | Universally_bound of Fresh_name.t
40 | Existentially_bound
41 end
42
43 (** Looks up the binding for a type variable. *)
44 val binding_kind : t -> string -> loc:location -> Binding_kind.t
45
46 (** Extends the renaming of a type declaration with GADT context for a constructor
47 declaration, if any. *)
48 val with_constructor_declaration
49 : t
50 -> constructor_declaration
51 -> type_parameters:string list
52 -> t