3 ms·
I really wish they'd taken the pipeline (|>) operator from F#, if they were going to rework OCaml.
by cwyers 10y ago
I really wish they'd taken the pipeline (|>) operator from F#, if they were going to rework OCaml.
- chenglou 10y agoThe pipe operator's still there.
- cwyers 10y agoI've never written OCaml, just SML and F#, but I thought that OCaml didn't have the |> operator.
- cvik 10y agoOCaml, like SML, have the syntax for defining their own operators. |> is defined, to my knowledge, both in the standard prelude and in core.
- gaius 10y agoSince Ocaml 4 if I remember correctly
- LeonidasXIV 10y ago4.01 to be exact. Along with @@, which is kinda comparable to $ in Haskell.
- thedufer 10y agoAs 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 10y agoCan be shortened to let (|>) x f = "%apply" which utilises some language magic and is probably faster.
- thedufer 10y agoAt 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`.