没有管道,F#无法调用Seq.fold?

use*_*836 1 f# f#-interactive

我正在忙着学习F#而且正在玩耍Seq.fold.任何人都可以解释为什么以下两个调用基本上不相同,一个错误,另一个没有.

以这种方式调用:

Seq.fold (fun state input -> state + input) 0 Seq.ofList [1;2;3;4;5];;
Run Code Online (Sandbox Code Playgroud)

导致以下错误:

error FS0001: This expression was expected to have type
    ''a -> 'b'
but here has type
    'int'
Run Code Online (Sandbox Code Playgroud)

调用管道工作正常:

Seq.ofList [1;2;3;4;5] |> Seq.fold (fun state input -> state + input) 0;;
Run Code Online (Sandbox Code Playgroud)

我猜我已经以某种方式采用了泛型函数并强制它只是int.

Foo*_*ole 7

您将Seq.ofList作为第三个参数传递给Seq.fold.你需要添加一些parens:

Seq.fold (fun state input -> state + input) 0 (Seq.ofList [1;2;3;4;5]);;