1

I have code in BuckleScript:

let add = (x, y) => x+y;
2 -> (3 -> add);

I would expect it to compile for obvious reasons. But it doesn't. I get

'|.' is not a valid value identifier.

Why? Cheers.

Yawar
  • 11,272
  • 4
  • 48
  • 80
Dominik Teiml
  • 505
  • 1
  • 4
  • 12

3 Answers3

4

It is a bug, just made a tentative fix!

bobzhang
  • 1,771
  • 3
  • 17
  • 19
1

The pipe first operator is only available when compiling Reason to JavaScript with BuckleScript (see docs for pipe first in the BuckleScript site).

If you are working on a native Reason project (or a project that uses the native compiler in the browser through js_of_ocaml, like sketch.sh) the pipe operator won't be available.

The reason why the error message shows |. is because the pipe operator is written as -> in Reason syntax and as |. in OCaml syntax.

See What's the difference between -> and |> in reasonml? for more details.

Javier Chávarri
  • 1,605
  • 11
  • 21
1

I don't know why you get this error specifically, but because a syntactic transform instead of an ordinary operator but, I suspect BuckleScript might not check for |. recursively and instead passes it through to the compiler which determines it to be an invalid "value identifier", whatever that means.

But in any case, I don't see how this would work in practice. It works well with |> because that's an ordinary operator which relies on currying. Every application of |> will "append" an argument and because of currying returns an actual value, either the final value or a partially applied function, e.g.:

3 |> add  <=>  add(3)  <=>  y => add(3, y)

What would a partial application of |. return? Currying doesn't work in the reverse. The only possibility is to return an explicit function that applies the last argument, e.g. x => add(x, 3), but that requires knowing the arity of the function and hence is no longer just a syntactic transform.

|. is in my opinion a nasty hack that doesn't fit naturally into the language, but has been forced into BuckleScript anyway and its use unfortunately seems to be encouraged despite its flaws and severely negative implications. My advice is (as usual) to avoid it. In Reason you can use |> _ instead when needed, e.g. 3 |> add(_, 2) <=> 3 -> add(2).

glennsl
  • 28,186
  • 12
  • 57
  • 75