Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
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

Closed
dotnet/try
#571

Description

@cartermp

The following code is required to get the nice formatting in F#:

System.Collections.Generic.Dictionary<string, int>([("zero", 0); ("one", 1); ("two", 2)])

image

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.
image

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.

Activity

  1. self-assigned this
    on Oct 25, 2019
  2. brettfo commented on Oct 28, 2019

    @brettfo
    Member

    The issue is exactly the opposite. The F# dict function returns an object that implements IDictionary<TKey, TValue>, but not IDictionary 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.

  3. transferred this issue fromdotnet/tryon Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions