let a = Map.Make<int, string>(fun x y  -> -(compare x y))

tells me it is only allowed for compatibility with OCaml

So what is the standard way of doing this in F# for a Map?

I'd go with this for now, or convert the Map keys to a List and run List.rev.

1
let b = a |> Map.to_list |> List.rev |> List.map (fun key -> blah a.[key]) 

And "yes", Map's are ordered.

By on 7/30/2009 8:20 AM ()

Ah, I stand corrected.

By on 7/30/2009 1:45 PM ()

If a mutable structure is acceptable, the System.Collections.Generic.SortedDictionary<'Key, 'Value> type from .Net 2.0 might help you with its IComparer-based constructor... See [link:msdn.microsoft.com]

By on 7/28/2009 4:07 PM ()

I'm using a Generics.Dictionary<> right now myself. It's acceptable of course, but it sort of defeats a primary purpose of using F#.

By on 7/28/2009 4:12 PM ()

Sounds like this is very much related to my other question.

I think maps are orderless, so to sort a map you would need to convert the keys and/or values to a sequence first. But you do need to be able to specify a comparer in order to override identification logic.

For instance, there's no way to specify whether the map keys are case sensitive or not.

By on 7/28/2009 7:36 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