You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Change default dictionary formatter to be IDictionary<TKey, TValue> #12
If the formatter works with IDictionary<TKey, TValue>, then the code can merely be this:
dict [("zero",0);("one",1);("two",2)]
Currently it falls back to the IEnumerablt<T> formatter.
This should allow the same formatting to apply to any code that has a result which implements that interface, such as those using immutable collections.
The issue is exactly the opposite. The F# dict function returns an object that implements IDictionary<TKey, TValue>, but notIDictionary explicitly, and since IDictionary<TKey, TValue> doesn't implement IDictionary (especially odd since IEnumerable<T> implements IEnumerable), you get the unexpected behavior. E.g., the incoming collection is matched against the generic IDictionary<TKey, TValue>here, but a few lines below the actual values are extracted assuming IDictionary (non-generic) here which doesn't work in the F# case you you instead get the simple IEnumerable that IDictionary<TKey, TValue>does implement.
From the F# side, the result of dict should implement IDictionary directly, but there's also the incorrect assumption in this code base that IDictionary<TKey, TValue> implies the implementation of IDictionary. It was just a happy accident that System.Collections.Generic.Dictionary<TKey, TValue> implements both.
Activity
brettfo commentedon Oct 28, 2019
The issue is exactly the opposite. The F#
dictfunction returns an object that implementsIDictionary<TKey, TValue>, but notIDictionaryexplicitly, and sinceIDictionary<TKey, TValue>doesn't implementIDictionary(especially odd sinceIEnumerable<T>implementsIEnumerable), you get the unexpected behavior. E.g., the incoming collection is matched against the genericIDictionary<TKey, TValue>here, but a few lines below the actual values are extracted assumingIDictionary(non-generic) here which doesn't work in the F# case you you instead get the simpleIEnumerablethatIDictionary<TKey, TValue>does implement.From the F# side, the result of
dictshould implementIDictionarydirectly, but there's also the incorrect assumption in this code base thatIDictionary<TKey, TValue>implies the implementation ofIDictionary. It was just a happy accident thatSystem.Collections.Generic.Dictionary<TKey, TValue>implements both.