It seems something has changed. Interestingly, the following works like a charm:

1
2
for Some(nm) in [ Some("James"); None; Some("John") ] do printfn "%d" nm.Length
By on 1/22/2009 7:30 AM ()

I hit the same problem in the same book. There is no errata on this (don't know where that would be submitted). It's now four builds back (1.9.2) from the current (1.9.6) version, maybe needs an update itself? Couldn't find a 1.9.2 version of the "informal" spec, so couldn't figure out anything there.

So, I verified that

1
2
3
4
5
6
7
8
seq { for x in [Some("John"); None; Some("James")] do 

      match x with 

         | Some(nm) -> yield nm 

         | _ -> ()};; 

works, but that seems a little verbose. How is everyone else dealing with this?

By on 6/10/2009 11:29 AM ()

For the book errata, see [link:www.expert-fsharp.com] (last update Jan 2009, we'll work on a new update today)

To submit new errata send direct to me (dsyme AT microsoft DOT com) or one of the other authors, or via the Apress site.

Thanks!

don

By on 6/12/2009 7:53 AM ()

Hmm. Strange that this works in a loop, but not in a sequence expression.
The way computation expressions are compiled did change between builds, so maybe that's what caused this.

You can get the desired result by using Seq.choose to grab only the Some(..) parts of the list, like this:

1
let thisworks = seq { for nm in [ Some("James"); None; Some("John") ] |> Seq.choose id -> nm.Length }
By on 6/11/2009 12:49 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper