为什么使用向后管道运算符解决编译错误?

Sco*_*rod 3 f# fscheck

编译器接受以下行:

input |> Prop.forAll <| fun (a , b) -> add a b = add b a
Run Code Online (Sandbox Code Playgroud)

但是,当我用括号替换向后pipline运算符时,我收到一个错误:

input |> Prop.forAll ( fun (a , b) -> add a b = add b a )
Run Code Online (Sandbox Code Playgroud)

类型不匹配.期待任意 - >'a但给定a('b - >'c) - >属性"任意"类型与"a - >"b类型不匹配

我不太清楚这个错误意味着什么.为什么向后管道操作符编译但括号不编译?

附录:

module Arithmetic

let add a b =
    a + b

open FsCheck
open FsCheck.Xunit

[<Property(MaxTest=1000, QuietOnSuccess=true)>]
let ``'a + 'b equals 'b + 'a`` () =

    // Declare generators per type required for function
    let intGenerator = Arb.generate<int>

    // Map previously declared generators to a composite generator 
    // to reflect all parameter types for function
    let compositeGenerator = (intGenerator , intGenerator) ||> Gen.map2(fun a b -> a , b)

    // Pull values from our composite generator
    let input = Arb.fromGen compositeGenerator

    // Apply values as input to function
    input |> Prop.forAll <| fun (a , b) -> add a b = add b a
Run Code Online (Sandbox Code Playgroud)

Fyo*_*kin 7

在第二行,您的参数输入顺序错误.

函数应用程序具有最高优先级,因此它首先应用于其他所有事物之前.运算符<||>在此之后应用,并且它们具有相同的优先级,因此首先应用左侧的操作符,然后应用右侧的操作符.所以如果你考虑这一行:

x |> y <| z
Run Code Online (Sandbox Code Playgroud)

首先应用左管道并获得:

(y x) <| z
Run Code Online (Sandbox Code Playgroud)

在应用正确的管道后,您将获得:

y x z
Run Code Online (Sandbox Code Playgroud)

但如果你考虑第二行,那就是另一种方式:

x <| y (z)
Run Code Online (Sandbox Code Playgroud)

应用管道后:

y (z) x
Run Code Online (Sandbox Code Playgroud)