You can allways "fallback" to the classes in System.Collection - for example the Dictionary class might be just the thing you need.

Of course it's not "pure" in the sense, that it's not inmutable but it might give you the performance increase you are looking for.

Greetings,

Carsten

By on 1/19/2009 9:15 PM ()

Thanks Tomas. Sometimes it is too easy ;-)

By on 1/20/2009 12:52 AM ()

Actually I'd always assumed that add would though an exception if the key already existed, and have quite a bit of code using maps where I do a delete before the add. Might be nice if the docs where a bit clear on this point!

[link:research.microsoft.com]

By on 1/20/2009 3:02 AM ()

Hi Steffen,
to update a value in the map, you can just call Map.add. If an element already exists, it will be updated. In most of the cases, this behavior largely simplifies the code. The remove function doesn't throw an exception if the element wasn't found, so the code you wrote will do exactly the same thing.

If you wanted to throw an exception if the element isn't present (e.g. to make the code more robust). You could write something like:

1
2
3
let update key v m = 
   ignore(Map.find key m)
   Map.add key v m;

T.

By on 1/19/2009 3:34 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