@@ -62,19 +62,42 @@ val apply :
6262
6363(* * GADT for function types.
6464
65- Given an arrow type ['a -> 'row], the following construct provides
66- a more precise representation of this function type than
67- [[%ty: 'a -> 'row] : ('a -> 'row) Ty.ty]:
65+ This abstract type fulfills a similar aim as the ['a Ty.ty] type:
66+ provide a type-safe way to build terms representing an OCaml type
67+ (relying on [Parsetree.core_type]), the type of these terms being
68+ themselves parameterized by the type at stake, in order to
69+ constrain the type of other arguments involved in the considered
70+ (grader) expression.
6871
69- [[%funty: 'a -> 'row] : (('a -> 'row) Ty.ty, 'a -> 'urow, 'ret) fun_ty]
72+ For ['a Ty.ty], this aim can be achived with the ppx expression
73+ [[%ty: int]], which builds an abstract term of type [int Ty.ty]
74+ (this term also gathering an appropriate encoding of the [int]
75+ type in terms of [Parsetree.core_type]).
7076
71- In particular, the codomain type ['ret] is made explicit, so that
72- if ['row = 'b -> 'c], we get ['urow = 'b -> unit] and ['ret = 'c].
77+ For implementing n-ary graders, this information is not sufficient
78+ in practice, notably as we need to make it explicit in the type
79+ annotation, what is the co-domain of the n-ary function at stake.
7380
74- Usage: [arg_ty [%ty: int] @@ arg_ty [%ty: string] @@
75- last_ty [%ty: bool] [%ty: unit]]
81+ This is achieved by the GADT
82+ [(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) fun_ty].
7683
77- Alternatively: [[%funty: int -> string -> bool -> unit]] *)
84+ There are two ways to build terms of this type:
85+
86+ 1. Use the two functions [arg_ty], [last_ty], and appropriate
87+ [[%ty: type]] expressions, for example:
88+
89+ [arg_ty [%ty: int] @@
90+ last_ty [%ty: string] [%ty: bool]];
91+
92+ 2. Use directly the [[%funty: 'ar -> 'row]] construct, for example:
93+
94+ [[%funty: int -> string -> bool]].
95+
96+ For both cases in this example, we get a term of type:
97+
98+ [((int -> string -> bool) Ty.ty, int -> string -> unit, bool) fun_ty],
99+
100+ where the co-domain type [bool] is now explicit. *)
78101type ('arrow, 'uarrow, 'ret) fun_ty
79102
80103(* * [last_ty [%ty: a] [%ty: r]] builds a function type for [a -> r] *)
0 commit comments