The F# Map/Set APIs don't support a custom comparer; if you want that functionality, you'd create a wrapper type for the key. E.g. create a "IgnoreCaseString" type that just holds a string and has an IComparable implementation that is case-insensitive, and then have the Map hold objects of that type (rather than strings) as keys.

By on 10/28/2009 3:51 PM ()

Actually, you can use a custom comparer if you use the Powerpack and Caml-compatibility functions. But this is somewhat cumbersome, and you don't have most of Map functions (the library improvements didn't apply to the fspack):

1
2
3
4
5
6
let M = Map.Make<string,int> (fun x y -> compare (x.ToLower()) (y.ToLower()))


let ducks = List.fold (fun acc (k,v) -> M.add k v acc) M.empty ["duck", 1; "Duck", 2; "Goose", 3]

Brian's suggestion is probably the best choice.

Laurent.

By on 10/29/2009 3:09 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