F#: always "unexpected 'when' keyword"

f#, syntax, visual-studio-2010

Solution

You want

[for i in 1..50 do
    if i < 10 then
        yield i]  

The 'short' syntax with 'when' was removed a while back. See

http://blogs.msdn.com/dsyme/archive/2008/08/29/detailed-release-notes-for-the-f-september-2008-ctp-release.aspx

and look for "compact sequence expressions" in that document.

Problem

The VS2010 Beta 2 F# compiler always complains about my usage of the when keyword, even when using copy-pasted code which is supposed to work, such as either of these snippets. For instance, this is the error I get when trying to execute a very trivial expression: "Error FS0010: Unexpected keyword 'when' in expression. Expected '->' or other token. " ``` [for i in 1..50 when i < 10 -> i] ---------------^^^^ ```

Original source