Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
cwyers
on May 17, 2016
|
parent
|
context
|
favorite
| on:
Reason: A new interface to OCaml
I really wish they'd taken the pipeline (|>) operator from F#, if they were going to rework OCaml.
thedufer
on May 18, 2016
|
next
[–]
As others have noted, the pipeline operator already exists in OCaml. And even if it didn't, you can define it pretty easily:
let (|>) x f = f x
LeonidasXIV
on May 18, 2016
|
parent
|
next
[–]
Can be shortened to
let (|>) x f = "%apply"
which utilises some language magic and is probably faster.
thedufer
on May 19, 2016
|
root
|
parent
|
next
[–]
At risk of being pedantic, that's actually shorter. It also doesn't work, at least on the version of OCaml I'm familiar with. In order to invoke that particular bit of "language magic", you'd have to declare it external and explicitly give its type:
external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
Also, `%apply` is usually the `@@` operator. For `|>`, one would expect `%revapply`.
chenglou
on May 17, 2016
|
prev
[–]
The pipe operator's still there.
cwyers
on May 18, 2016
|
parent
[–]
I've never written OCaml, just SML and F#, but I thought that OCaml didn't have the |> operator.
cvik
on May 18, 2016
|
root
|
parent
[–]
OCaml, like SML, have the syntax for defining their own operators. |> is defined, to my knowledge, both in the standard prelude and in core.
gaius
on May 18, 2016
|
root
|
parent
[–]
Since Ocaml 4 if I remember correctly
LeonidasXIV
on May 18, 2016
|
root
|
parent
[–]
4.01 to be exact. Along with @@, which is kinda comparable to $ in Haskell.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: