是否可以在OCaml中使用管道? [英] Is it possible to use pipes in OCaml?

查看:87
本文介绍了是否可以在OCaml中使用管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在F#中,我不能没有管道(<||>)

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

我可以在OCaml中使用<||>吗?

Can I use <| and |> in OCaml?

推荐答案

这些自OCaml 4.01起可用.但是,<|在此处被命名为@@,因此它具有正确的运算符关联性.

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

或者您使用随附的迷彩电池,其中已定义了|><|运算符在BatStd中.

Or you use Ocaml batteries included, which has the |> and <| operators defined in BatStd.

这篇关于是否可以在OCaml中使用管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆