Is it possible to use pipes in OCaml?

断了今生、忘了曾经 提交于 2020-01-01 07:34:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!