Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for |> in uncurried mode by desugaring it #6083

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ These are only breaking changes for unformatted code.
- Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851
- 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
- PPX V3: allow uncurried `make` function and treat it like a curried one https://github.com/rescript-lang/rescript-compiler/pull/6081
- Add support for `|>` in uncurried mode by desugaring it https://github.com/rescript-lang/rescript-compiler/pull/6083

# 10.1.4

Expand Down
13 changes: 10 additions & 3 deletions res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2204,9 +2204,16 @@ and parseBinaryExpr ?(context = OrdinaryExpr) ?a p prec =
let b = parseBinaryExpr ~context p tokenPrec in
let loc = mkLoc a.Parsetree.pexp_loc.loc_start b.pexp_loc.loc_end in
let expr =
Ast_helper.Exp.apply ~loc
(makeInfixOperator p token startPos endPos)
[(Nolabel, a); (Nolabel, b)]
match (token, b.pexp_desc) with
| BarGreater, Pexp_apply (funExpr, args)
when p.uncurried_config = Uncurried ->
{b with pexp_desc = Pexp_apply (funExpr, args @ [(Nolabel, a)])}
| BarGreater, _ when p.uncurried_config = Uncurried ->
Ast_helper.Exp.apply ~loc b [(Nolabel, a)]
| _ ->
Ast_helper.Exp.apply ~loc
(makeInfixOperator p token startPos endPos)
[(Nolabel, a); (Nolabel, b)]
in
Parser.eatBreadcrumb p;
loop expr)
Expand Down
7 changes: 7 additions & 0 deletions res_syntax/tests/printer/expr/Uncurried.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@@uncurried

let add3 = (x,y,z) => x+y+z

let triangle = 3 |> add3(1,2) |> add3(4,5)

let () = 3 |> ignore
7 changes: 7 additions & 0 deletions res_syntax/tests/printer/expr/expected/Uncurried.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@@uncurried

let add3 = (x, y, z) => x + y + z

let triangle = add3(4, 5, add3(1, 2, 3))

let () = ignore(3)