问题
In F# I can't live without pipes (<| and |>)
let console(dashboard : Dashboard ref) =
let rec eat (command : string) =
command.Split(' ','(',')')
|> Seq.filter(fun s -> s.Length <> 0)
|> fun C ->
(Seq.head C).ToUpper() |> fun head ->
Can I use <| and |> in OCaml?
回答1:
These are available since OCaml 4.01. However, <| is named @@ there, so it has the correct operator associativity.
Alternatively, you can either define them yourself:
let (|>) v f = f v
let (<|) f v = f v (* or: *)
let (@@) f v = f v
Or you use Ocaml batteries included, which has the |> and <| operators defined in BatStd.
来源:https://stackoverflow.com/questions/8986010/is-it-possible-to-use-pipes-in-ocaml