Skip to content

Spurious FS3570 warning with Active Pattern #16410

@ghost

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))
        )

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions