fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Improve compilation error when parametrizing non-partial active patterns

Open cmeeren opened this issue 3 years ago • 0 comments

As I understand it, non-partial active patterns may not have extra parameters:

let inline (|Lt|Gt|Eq|) compareWith x =
  if x < compareWith then Lt
  elif x > compareWith then Gt
  else Eq

match 2 with
| Lt 3 -> ()
//^^^^
// Type mismatch. Expecting a 'int -> Choice<'a,'b,'c>' but given a
// 'int -> int -> Choice<unit,unit,unit>' The type 'Choice<'a,'b,'c>'
// does not match the type 'int -> Choice<unit,unit,unit>'

The error is very confusing. It would be better to have an error on the active pattern definition itself.

cmeeren avatar Apr 02 '22 19:04 cmeeren