将F#管道运算符(

栏目: ASP.NET · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/14410953/converting-f-pipeline-operators-to-ocaml
我正在将一些F#代码转换为OCaml,我看到这个管道运算符的大量用法<

|,例如:

let printPeg expr =
    printfn "%s" <| pegToString expr

<|运算符显然定义为:

# let ( <| ) a b = a b ;;
val ( <| ) : ('a -> 'b) -> 'a -> 'b = <fun>

我想知道为什么他们懒得在F#中定义和使用这个操作符,是不是就这样它们可以避免像这样放入这样的parens?:

let printPeg expr =
    Printf.printf "%s" ( pegToString expr )

据我所知,这将是上面的F#代码转换为OCaml,对吗?

另外,我将如何实现F#的< > Ocaml的操作符?和>

(|>运算符似乎只是:let(|>)a b = b a ;;)

直接来自 F# source
let inline (|>) x f = f x
let inline (||>) (x1,x2) f = f x1 x2
let inline (|||>) (x1,x2,x3) f = f x1 x2 x3
let inline (<|) f x = f x
let inline (<||) f (x1,x2) = f x1 x2
let inline (<|||) f (x1,x2,x3) = f x1 x2 x3
let inline (>>) f g x = g(f x)
let inline (<<) f g x = f(g x)

翻译自:https://stackoverflow.com/questions/14410953/converting-f-pipeline-operators-to-ocaml


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms and Data Structures

Algorithms and Data Structures

Kurt Mehlhorn、Peter Sanders / Springer / 2008-08-06 / USD 49.95

Algorithms are at the heart of every nontrivial computer application, and algorithmics is a modern and active area of computer science. Every computer scientist and every professional programmer shoul......一起来看看 《Algorithms and Data Structures》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换