Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1006 Bytes

5012.md

File metadata and controls

38 lines (28 loc) · 1006 Bytes

5012

A binding, like with val, was not exhaustive.

This is effectively the same error as 5011, but for singular bindings.

datatype d = A of string | B of int | C of bool

fun f (x : d) : string =
  let
    val A y = x
(**     ^^^ non-exhaustive binding: missing `B _`, `C _` *)
  in
    y
  end

The pattern in a val binding ought to be "irrefutable", to wit, it alone ought to match all possible values of the type of the expression. For example:

  • The wildcard pattern _ is irrefutable.
  • Variable patterns like x and y are irrefutable.
  • Tuple patterns composed of irrefutable patterns are irrefutable.
  • If a datatype has only one constructor, then a pattern of that constructor, additionally with an irrefutable pattern argument if one is needed, is irrefutable.

To fix

Use a case or similar instead.

datatype d = A of string | B of int | C of bool

fun f (x : d) : string =
  case x of
    A s => s
  | B i => Int.toString i
  | C b => Bool.toString b