简体   繁体   中英

F#: expected 'in' or other token error

So I've written a pretty simple program in F# that should sum all of the multiples of 3 and 5 below 1000:

[1..999]
|> List.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> let total = List.sum`

However, at the very end of the program I get the following error:

Unexpected end of input in expression. Expected 'in' or other token.

I am using the lightweight syntax, so I'm not sure why F# would want me to use an 'in' statement. Any thoughts?

You probably intended to do this:

let total = 
  [1..999]
  |> List.filter (fun x -> x % 3 = 0 || x % 5 = 0)
  |> List.sum

The error message you are getting is because it expects a function after the forward pipe, you can have a let binding but as part of a function expecting at least one parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM