Comparing F# Map to Dictionary<TKey,TValue>
F# Map
is equal to .NET BCL Dictionary<TKey,TValue>
conceptually because they both implement .NET IDictionary<TKey,TValue>
. But F# Map
is semantically different from Dictionary<TKey,TValue>
.
Note
Please do not confuse F# Map
as type with F# Map
as a module. F# Map
as a module is called Map
. From outside, it is called by referencing to the namespace of FSharp.Collection.Map
module. The F# Map
as a type is available from outside F#. The name is called FSharpMap
.
From the performance perspective, it is still faster because of its immutability behavior.
From the correctness perspective, F# Map
is enforcing us to be more correct because of the constrained key and value of the generic type parameter.
Let's look at the type definition signature of F# Map
:
type Map<[<EqualityConditionalOn>]''Key, [<EqualityConditionalOn;ComparisonConditionalOn>]'Value when 'Key : comparison >(comparer: IComparer<''Key>, tree: MapTree...