dotnet / dotnet/fsharp

Error message improvement: when pattern matching has arity mismatch

Open
#5,568 4 comments 2 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

When matching on a discriminated union I need to match all values individually even when all I want to match the tuple. I am new to F# so this could very well be the correct semantics but in Standard ML (and I believe OCaml) this would just work -- it feels like a bug.

#### Repro steps
Consider this type:

type 'a Digit =
| D1 of 'a
| D2 of 'a * 'a
| D3 of 'a * 'a * 'a
| D4 of 'a * 'a * 'a * 'a

Of the following 3 functions f1, f2 compile fine, but f3 fails to compile. I want to use the tuple on the right hand side of -> (and not have to rebuild it) but I simply can't.

let f1 d =
match d with
| D1 x0 -> 1
| D2 (x0, x1) -> 2
| D3 (x0, x1, x2) -> 3
| D4 (x0, x1, x2, x3) -> 4

let f2 d =
match d with
| D1 _ -> 1
| D2 _ -> 2
| D3 _ -> 3
| D4 _ -> 4

let f3 d =
match d with
| D1 x -> 1
| D2 x -> 2
| D3 x -> 3
| D4 x -> 4

#### Expected behavior
All 3 should compile.

#### Actual behavior

Only f1 and f2 compile.

#### Known workarounds

Use version f1

#### Related information

Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Community

Visual F# 2015 00322-20000-00000-AA209
Microsoft Visual F# 2015

Visual F# Power Tools 2.5.6
A collection of additional commands for F# in Visual Studio

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.