本文介绍了为什么要使用向后管道运算符而不是函数链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要使用后向管道运算符而不是函数链接?

Why use a backward pipe operator instead of a function chaining?

let distanceFromOrigin aPoint =
    let square x = x * x
    sqrt (square aPoint.x + square aPoint.y)

vs

let distanceFromOrigin aPoint =
    let square x = x * x
    sqrt <| square aPoint.x + square aPoint.y

我发现

推荐答案

由于左侧的关联性(f <| g <| x被解析为(f <| g) <| x,而不幸地不是f <| (g <| x),其等效于x |> g |> f),我发现仅当您想删除括号时才有用(写f <| long expression代替f (long expression)).

Because of the left associativity (f <| g <| x is parsed as (f <| g) <| x and sadly not as f <| (g <| x) which is equivalent to x |> g |> f), I found it useful only when you want to remove parentheses (instead of f (long expression), you write f <| long expression).

这篇关于为什么要使用向后管道运算符而不是函数链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 16:51