Skip to content

Spurious FS3570 warning with Active Pattern #16410

Description

With F# 8, the following code generates an FS3570 warning about ambiguous "", even though there is only one use of "" (_.Add(k)):

open System.Collections.Generic

module Map =
    let update empty k f m =
        match Map.tryFind k m with
        | Some v -> Map.add k (f v) m
        | None -> Map.add k (f empty) m

let invert (dict: IDictionary<'k,#seq<'k>>): Map<'k,Set<'k>> =
    (Map.empty, dict)
    ||> Seq.fold (fun res (KeyValue (k, ks)) ->
            (res, ks)
            ||> Seq.fold (fun res vk -> res |> Map.update Set.empty vk _.Add(k))
        )

Rewriting to remove the (|KeyValue|) active pattern gets rid of the warning:

let invert (dict: IDictionary<'k,#seq<'k>>): Map<'k,Set<'k>> =
    (Map.empty, dict)
    ||> Seq.fold (fun res kvp ->
            (res, kvp.Value)
            ||> Seq.fold (fun res vk -> res |> Map.update Set.empty vk _.Add(kvp.Key))
        )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions