Hi, there. By default (at the time of writing), F# doesn't add references to .NET Framework 3.5 DLLs, so you need to do this manually:

#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5"
#r "System.Core.dll"
#r "System.Xml.Linq.dll"

after which you need to import necessary namespaces:

open System.Linq
open System.Collections.Generic
open System.Xml.Linq

Now you can go with LINQ to Objects and LINQ to XML.

One more thing, F# doesn't seem to recognize (and support) extension methods (I think that's because the current version of F# was built on top of .NET Framework 2.0 instead of 3.5, correct me if I'm wrong). Therefore you cannot use dot notation to access those methods defined within Enumerable class as you can in C#. Pipeline operator (|>) can help but a bit of addition work is required. Take Enumerable.First() method as an example, you need to first define a first funcation as follows:

let first (coll: #seq<'a>) = Enumerable.First<_>(coll)

Then you can go on with you collection:

{ 1..10 } |> first

Hope that helps.

By on 7/11/2008 6:04 AM ()

ok I just found the Seq.nth 0 function to do this.

contents |> Seq.nth 0
or better
Seq.hd contents

thx

By on 7/11/2008 5:08 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