Question about BuckleScript's |. pipe operator


#1

`
let foo a b = a - b;;

let r =
a
|. (foo b)
|. bar
;;
r was compiled tobar(foo(a, b))`, is that an bug?


#2

Why do you think it’s a bug?

Fast pipe puts the argument from the left to the first position, so foo(a, b) sounds about right.
Now, if you’d use a |> foo b, that would compile to foo(b, a).

Here’s a great article on fast pipe vs regular OCaml pipe: https://www.javierchavarri.com/data-first-and-data-last-a-comparison/

(Or did you expect that since you’ve put parentheses around foo b, the compiler would create a partially applied version of foo?)


#3

Thanks a lot. This is confusing when using parentheses, I think it’s better that the compiler would create a partially applied version of foo.


#4

Well, in your particular case, you can easily use the slow pipe: a |> foo b, |> bar, since bar is unary anyway and there’s no difference between t-first and t-last.

For more complicated cases, there are pipe placeholders.

The fast pipe precedence in BuckleScript is a complicated story(1, 2), so better not rely on parentheses, I guess.


#5

sorry for the confusion. The thing is in ast level, the paren is not distinguishable


#6

Thanks. If I want to use parentheses, |> would be a better choice in this case. :smile: