@@ -14,6 +14,13 @@ let init () =
14
14
{
15
15
structure_gen =
16
16
(fun (tdcls : tdcls ) _explict_nonrec ->
17
+ let handle_uncurried_accessor_tranform ~loc ~arity accessor =
18
+ (* Accessors with no params (arity of 0) are simply values and not functions *)
19
+ match Config. uncurried.contents with
20
+ | Uncurried when arity > 0 ->
21
+ Ast_uncurried. uncurriedFun ~loc ~arity accessor
22
+ | _ -> accessor
23
+ in
17
24
let handle_tdcl tdcl =
18
25
let core_type =
19
26
Ast_derive_util. core_type_of_type_declaration tdcl
@@ -39,7 +46,9 @@ let init () =
39
46
(Pat. constraint_ (Pat. var {txt; loc}) core_type)
40
47
(Exp. field
41
48
(Exp. ident {txt = Lident txt; loc})
42
- {txt = Longident. Lident pld_label; loc})))
49
+ {txt = Longident. Lident pld_label; loc})
50
+ (* arity will alwys be 1 since these are single param functions*)
51
+ |> handle_uncurried_accessor_tranform ~arity: 1 ~loc ))
43
52
| Ptype_variant constructor_declarations ->
44
53
Ext_list. map constructor_declarations
45
54
(fun
@@ -94,7 +103,8 @@ let init () =
94
103
annotate_type
95
104
in
96
105
Ext_list. fold_right vars exp (fun var b ->
97
- Ast_compatible. fun_ (Pat. var {loc; txt = var}) b)))
106
+ Ast_compatible. fun_ (Pat. var {loc; txt = var}) b)
107
+ |> handle_uncurried_accessor_tranform ~loc ~arity ))
98
108
| Ptype_abstract | Ptype_open ->
99
109
Ast_derive_util. notApplicable tdcl.ptype_loc derivingName;
100
110
[]
@@ -103,6 +113,13 @@ let init () =
103
113
Ext_list. flat_map tdcls handle_tdcl);
104
114
signature_gen =
105
115
(fun (tdcls : Parsetree.type_declaration list ) _explict_nonrec ->
116
+ let handle_uncurried_type_tranform ~loc ~arity t =
117
+ match Config. uncurried.contents with
118
+ (* Accessors with no params (arity of 0) are simply values and not functions *)
119
+ | Uncurried when arity > 0 ->
120
+ Ast_uncurried. uncurriedType ~loc ~arity t
121
+ | _ -> t
122
+ in
106
123
let handle_tdcl tdcl =
107
124
let core_type =
108
125
Ast_derive_util. core_type_of_type_declaration tdcl
@@ -119,7 +136,10 @@ let init () =
119
136
| Ptype_record label_declarations ->
120
137
Ext_list. map label_declarations (fun {pld_name; pld_type} ->
121
138
Ast_comb. single_non_rec_val ?attrs:gentype_attrs pld_name
122
- (Ast_compatible. arrow core_type pld_type))
139
+ (Ast_compatible. arrow core_type pld_type
140
+ (* arity will alwys be 1 since these are single param functions*)
141
+ |> handle_uncurried_type_tranform ~arity: 1
142
+ ~loc: pld_name.loc))
123
143
| Ptype_variant constructor_declarations ->
124
144
Ext_list. map constructor_declarations
125
145
(fun
@@ -135,6 +155,7 @@ let init () =
135
155
| Pcstr_tuple pcd_args -> pcd_args
136
156
| Pcstr_record _ -> assert false
137
157
in
158
+ let arity = pcd_args |> List. length in
138
159
let annotate_type =
139
160
match pcd_res with
140
161
| Some x -> x
@@ -143,7 +164,8 @@ let init () =
143
164
Ast_comb. single_non_rec_val ?attrs:gentype_attrs
144
165
{loc; txt = Ext_string. uncapitalize_ascii con_name}
145
166
(Ext_list. fold_right pcd_args annotate_type (fun x acc ->
146
- Ast_compatible. arrow x acc)))
167
+ Ast_compatible. arrow x acc)
168
+ |> handle_uncurried_type_tranform ~arity ~loc ))
147
169
| Ptype_open | Ptype_abstract ->
148
170
Ast_derive_util. notApplicable tdcl.ptype_loc derivingName;
149
171
[]
0 commit comments