Skip to content

Commit b140da1

Browse files
committed
Add support for |> in uncurried mode by desugaring it
Desugar the semantics of `|>` in uncurried mode so existing curried code still compiles. But the code will stop using `|>` after formatting. For example: `3 |> add3(1,2)` would not compile when `add3` has 3 arguments. But after desugaring, the third argument is added.
1 parent 7d93780 commit b140da1

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ These are only breaking changes for unformatted code.
7272
- Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851
7373
- New internal representation for uncurried functions using built-in type `function$<fun_type, arity>` this avoids having to declare all the possible arities ahead of time https://github.com/rescript-lang/rescript-compiler/pull/5870
7474
- PPX V3: allow uncurried `make` function and treat it like a curried one https://github.com/rescript-lang/rescript-compiler/pull/6081
75+
- Add support for `|>` in uncurried mode by desugaring it https://github.com/rescript-lang/rescript-compiler/pull/6083
7576

7677
# 10.1.4
7778

Diff for: res_syntax/src/res_core.ml

+10-3
Original file line numberDiff line numberDiff line change
@@ -2204,9 +2204,16 @@ and parseBinaryExpr ?(context = OrdinaryExpr) ?a p prec =
22042204
let b = parseBinaryExpr ~context p tokenPrec in
22052205
let loc = mkLoc a.Parsetree.pexp_loc.loc_start b.pexp_loc.loc_end in
22062206
let expr =
2207-
Ast_helper.Exp.apply ~loc
2208-
(makeInfixOperator p token startPos endPos)
2209-
[(Nolabel, a); (Nolabel, b)]
2207+
match (token, b.pexp_desc) with
2208+
| BarGreater, Pexp_apply (funExpr, args)
2209+
when p.uncurried_config = Uncurried ->
2210+
{b with pexp_desc = Pexp_apply (funExpr, args @ [(Nolabel, a)])}
2211+
| BarGreater, _ when p.uncurried_config = Uncurried ->
2212+
Ast_helper.Exp.apply ~loc b [(Nolabel, a)]
2213+
| _ ->
2214+
Ast_helper.Exp.apply ~loc
2215+
(makeInfixOperator p token startPos endPos)
2216+
[(Nolabel, a); (Nolabel, b)]
22102217
in
22112218
Parser.eatBreadcrumb p;
22122219
loop expr)

Diff for: res_syntax/tests/printer/expr/Uncurried.res

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@@uncurried
2+
3+
let add3 = (x,y,z) => x+y+z
4+
5+
let triangle = 3 |> add3(1,2) |> add3(4,5)
6+
7+
let () = 3 |> ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@@uncurried
2+
3+
let add3 = (x, y, z) => x + y + z
4+
5+
let triangle = add3(4, 5, add3(1, 2, 3))
6+
7+
let () = ignore(3)

0 commit comments

Comments
 (0)