Skip to content

Commit 2c96b79

Browse files
committed
Begin adding an arrow construction to Ast_helper that takes a list of arguments.
The arity is inferred, by just the length of the list of arguments.
1 parent bf020e9 commit 2c96b79

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

compiler/frontend/ast_core_type.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ let from_labels ~loc arity labels : t =
9393
(Ext_list.map2 labels tyvars (fun x y -> Parsetree.Otag (x, [], y)))
9494
Closed
9595
in
96-
Ext_list.fold_right2 labels tyvars result_type
97-
(fun label (* {loc ; txt = label }*) tyvar acc ->
98-
Ast_helper.Typ.arrow ~loc:label.loc ~arity:(Some arity)
99-
{lbl = Asttypes.Labelled label; typ = tyvar}
100-
acc)
96+
let args =
97+
Ext_list.map2 labels tyvars (fun label tyvar ->
98+
{Parsetree.lbl = Asttypes.Labelled label; typ = tyvar})
99+
in
100+
Typ.arrows ~loc args result_type
101101

102102
let make_obj ~loc xs = Typ.object_ ~loc xs Closed
103103

compiler/ml/ast_helper.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ module Typ = struct
5656
let var ?loc ?attrs a = mk ?loc ?attrs (Ptyp_var a)
5757
let arrow ?loc ?attrs ~arity arg ret =
5858
mk ?loc ?attrs (Ptyp_arrow {arg; ret; arity})
59+
let arrows ?loc ?attrs args ret =
60+
let arity = Some (List.length args) in
61+
let rec build_arrows arity_to_use = function
62+
| [] -> ret
63+
| [arg] -> arrow ?loc ?attrs ~arity:arity_to_use arg ret
64+
| arg :: rest ->
65+
arrow ?loc ?attrs ~arity:arity_to_use arg (build_arrows None rest)
66+
in
67+
build_arrows arity args
5968
let tuple ?loc ?attrs a = mk ?loc ?attrs (Ptyp_tuple a)
6069
let constr ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_constr (a, b))
6170
let object_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_object (a, b))

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module Typ : sig
5656
val var : ?loc:loc -> ?attrs:attrs -> string -> core_type
5757
val arrow :
5858
?loc:loc -> ?attrs:attrs -> arity:arity -> arg -> core_type -> core_type
59+
val arrows : ?loc:loc -> ?attrs:attrs -> arg list -> core_type -> core_type
5960
val tuple : ?loc:loc -> ?attrs:attrs -> core_type list -> core_type
6061
val constr : ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type
6162
val object_ :

0 commit comments

Comments
 (0)