Given the following expression to sum an IEnumerable of numbers:
let sum l = l |> Seq.reduce(+) //version a
is it possible to eliminate the argument--like so?
let sum = Seq.reduce(+) //version b
I get an error from the F# compiler (FS0030) and I seem to recall having seen something about an "eta conversion" being involved but unfortunately my knowledge of lambda calc is too limited to follow how eta conversion is involved.
Can the argument be eliminated as in version b?
Would someone please point me to literature that would explain an eta conversion and how it would come into play in this particular piece of code?
FS0030:
stdin(1,5): error FS0030: Value restriction. The value 'sum' has been
inferred to have generic type
val sum : ('_a -> int) when '_a :> seq Either make the arguments to 'sum' explicit or, if you do not intend for it to be
generic, add a type annotation.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…