Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F#: always "unexpected 'when' keyword"

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]  
---------------^^^^
like image 754
Martin Avatar asked Dec 04 '09 22:12

Martin


2 Answers

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.

like image 155
Brian Avatar answered Oct 23 '22 23:10

Brian


You should use the yield keyword now. Like that:

[for i in 1 .. 50 do if i < 10 then yield i]
like image 40
Stringer Avatar answered Oct 24 '22 01:10

Stringer