La ligne suivante est acceptée par le compilateur:Pourquoi l'utilisation d'un opérateur de pipeline en amont résout-elle une erreur de compilation?
input |> Prop.forAll <| fun (a , b) -> add a b = add b a
Cependant, quand je remplace l'opérateur Pipline en arrière avec des parenthèses, je reçois une erreur:
input |> Prop.forAll (fun (a , b) -> add a b = add b a)
Type mismatch. Expecting a Arbitrary -> 'a but given a ('b -> 'c) -> Property The type 'Arbitrary' does not match the type ''a -> 'b
Je ne suis pas tout à fait sûr de ce que cette erreur signifie. Pourquoi l'opérateur de pipeline en amont compile-t-il mais pas les parenthèses?
Annexe:
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
Vous pouvez utiliser 'Arb.generate' et détruire complètement 'compositeGenerator'. –
Wow, jamais même considéré que ... Merci! –