Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I really wish they'd taken the pipeline (|>) operator from F#, if they were going to rework OCaml.


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


Can be shortened to

    let (|>) x f = "%apply"
which utilises some language magic and is probably faster.


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`.


The pipe operator's still there.


I've never written OCaml, just SML and F#, but I thought that OCaml didn't have the |> operator.


OCaml, like SML, have the syntax for defining their own operators. |> is defined, to my knowledge, both in the standard prelude and in core.


Since Ocaml 4 if I remember correctly


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: