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

[Syntax]Pipe operator (reverse application) #457

Merged
merged 1 commit into from
Nov 10, 2021

Conversation

yannham
Copy link
Member

@yannham yannham commented Nov 10, 2021

Close #455. Add a reverse application operator to nicely write a sequence of transformation as something like a Unix pipeline.

Usually you want this operator to not take precedence too much, to avoid parentheses around the initial expression such as x * 2 |> nums.pow 2 and such that it can also serve as a Haskell's $, just reversed. I put it at a similar precedence level as in OCaml, where it takes higher precedence than boolean operators like && and ||. However Haskell's $ and Elm |> take the lowest precedence of all operators, even than boolean ones. I'm not sure how much it matters: should foo && bar |> stuff |> otherstuff be interpreted as foo && (bar |> stuff |> otherstuff) or (foo && bar) |> stuff |> otherstuff? I don't have a strong opinion, although I arbitrarily prefer the first option, as is implemented in this PR.

@yannham yannham requested a review from thufschmitt November 10, 2021 10:56
@github-actions github-actions bot temporarily deployed to pull request November 10, 2021 11:05 Inactive
Copy link
Contributor

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should foo && bar |> stuff |> otherstuff be interpreted as foo && (bar |> stuff |> otherstuff) or (foo && bar) |> stuff |> otherstuff?

I don’t have a strong opinion either, I think either case can make sense or be utterly confusing depending on the line-breaks and indentation. So let’s stick with the first one.

(If anything, the bit where I’d like this to have a very weak precedence is wrt | and :, so that we can write

x
  |> lists.map (fun x => x - 1) : Num -> Num
  |> lists.filter (fun x => x > 2) : Num -> Bool

but that sounds like a false good idea, so let’s forget about it)

@thufschmitt thufschmitt merged commit 70dee56 into master Nov 10, 2021
@thufschmitt thufschmitt deleted the feature/pipe-operator branch November 10, 2021 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pipe operator (not the one we have, but reverse application)
2 participants