int/string 的类型似乎导致了错误

type of int/string seems to be causing error

我收到以下错误

error FS0019: This constructor is applied to 0 argument(s)

来自这个代码

type Expression = Number of int | Operator of string | WhiteSpace of string

let IsNotWhiteSpace expression =
    match expression with 
    | Number | Operator -> true 
    | WhiteSpace -> false

我没有从中得到任何红线,它只在我编译时显示。我 运行 不知道是什么原因造成的。如果有人能给我解释一下,我会很想吃的。

您必须将构造函数中的 int 或字符串值匹配到一个变量中,例如

let IsNotWhiteSpace expression =
  match expression with 
  | Number n -> true 
  | Operator o -> true 
  | WhiteSpace w -> false

由于您不需要这些值,您也可以使用 _

丢弃它们
let IsNotWhiteSpace expression =
  match expression with 
  | Number _ | Operator _ -> true 
  | WhiteSpace _ -> false