编译器接受以下行:
input |> Prop.forAll <| fun (a , b) -> add a b = add b a
但是,当我用括号替换向后管道运算符时,我收到一个错误:
input |> Prop.forAll ( fun (a , b) -> add a b = add b a )
类型不匹配。期望任意 -> 'a 但给定 a ('b -> 'c) -> 属性 'Arbitrary' 类型与类型 ''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