我用f#编写了一个非常简单的程序,它应该对1000以下的所有3和5的倍数求和:
[1..999]
|> List.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> let total = List.sum`
然而,在程序的最后,我得到了以下错误:
Unexpected end of input in expression. Expected 'in' or other token.
我正在使用轻量级语法,所以我不确定为什么f#会希望我使用'in'语句。任何想法吗?
您可能打算这样做:
let total =
[1..999]
|> List.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> List.sum
你得到的错误消息是因为它期望在转发管道之后有一个函数,你可以有一个let绑定,但是作为期望至少一个参数的函数的一部分。