The List.ofSeq function (or equivalently, the Seq.toList function) will convert any 'a seq (which is just an alias for

1
IEnumerable<'a>

) into an 'a list. However, depending on your use case this may not really be what you want, since F# lists are immutable linked lists - what are you trying to do once you have the data?

EDIT - Or in other words, what Brian said...

By on 4/11/2010 11:28 AM ()

Thank you for the quick reply.

One part of my windows app manages 'contacts'; names, addresses, phone, the usual.

I had planned to create an F# list with all the contacts, and as the user entered info into the 'contact form', the app would match the input with records in the list.

My goal was to be fast, not have to hit SQL with every new character, and most importantly, learn some F#. But I was immediately tripped up with the task of creating a list from the contact data.

Did I miss the point on what lists are best used for?

Thanks

By on 4/11/2010 12:17 PM ()

If you just need an in-memory structure to cache the contents, an array will work fine, and give you fast random access and mutable updates if you need that.

More to the point, for tens of thousands of records, arrays will have better memory performance than lists.

By on 4/11/2010 5:03 PM ()

Thanks for the info about the arrays and sequences.

By on 4/11/2010 7:04 PM ()

from the description of it, I doubt array is the right thing as it very much sounds like the access would be key based(sort of in-memory SQL table style access).

A dictionary or LINQ over sqlite in-memory table or the good old DataView may be a better choice. Array only gives you fast integer indexed based access(and update) but insertion/addition can be slow(?)

By on 4/11/2010 10:51 PM ()

First off, it seems unlikely you would want to do this (F# lists are rarely useful for this much data).

That said, you can create a list from any sequence/IEnumerable using either

Seq.toList

or

List.ofSeq

You could even create one using

[ for x in originalSeq do yield x ]

Note that there's no such thing as an "F# array"; an F# array and a C# array are both the same .NET array object type.

By on 4/11/2010 11:22 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