int / string类型似乎引起错误

我收到以下错误

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

我没有从中得到任何红线,它仅在编译时显示。我对可能导致这种情况的想法已经用尽。如果有人可以向我解释这一点,我会很高兴。

评论
  • xsint
    xsint 回复

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

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

    Since you don't need the values, you can also discard them using _

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