@@ -14,6 +14,13 @@ let init () =
1414 {
1515 structure_gen =
1616 (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
1724 let handle_tdcl tdcl =
1825 let core_type =
1926 Ast_derive_util. core_type_of_type_declaration tdcl
@@ -39,7 +46,9 @@ let init () =
3946 (Pat. constraint_ (Pat. var {txt; loc}) core_type)
4047 (Exp. field
4148 (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 ))
4352 | Ptype_variant constructor_declarations ->
4453 Ext_list. map constructor_declarations
4554 (fun
@@ -94,7 +103,8 @@ let init () =
94103 annotate_type
95104 in
96105 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 ))
98108 | Ptype_abstract | Ptype_open ->
99109 Ast_derive_util. notApplicable tdcl.ptype_loc derivingName;
100110 []
@@ -103,6 +113,13 @@ let init () =
103113 Ext_list. flat_map tdcls handle_tdcl);
104114 signature_gen =
105115 (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
106123 let handle_tdcl tdcl =
107124 let core_type =
108125 Ast_derive_util. core_type_of_type_declaration tdcl
@@ -119,7 +136,10 @@ let init () =
119136 | Ptype_record label_declarations ->
120137 Ext_list. map label_declarations (fun {pld_name; pld_type} ->
121138 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))
123143 | Ptype_variant constructor_declarations ->
124144 Ext_list. map constructor_declarations
125145 (fun
@@ -135,6 +155,7 @@ let init () =
135155 | Pcstr_tuple pcd_args -> pcd_args
136156 | Pcstr_record _ -> assert false
137157 in
158+ let arity = pcd_args |> List. length in
138159 let annotate_type =
139160 match pcd_res with
140161 | Some x -> x
@@ -143,7 +164,8 @@ let init () =
143164 Ast_comb. single_non_rec_val ?attrs:gentype_attrs
144165 {loc; txt = Ext_string. uncapitalize_ascii con_name}
145166 (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 ))
147169 | Ptype_open | Ptype_abstract ->
148170 Ast_derive_util. notApplicable tdcl.ptype_loc derivingName;
149171 []
0 commit comments