我有学校课程(有2个构造函数):
type School(name, antiquity) =
member this.Name: string = name
member this.Antiquity: int = antiquity
new(name) = School(name, 0)
建筑类型:
type Building =
| House
| School of School
我想知道具有“knowType”功能的建筑物的类型:
let knowType building =
match building with
| House -> "A house!"
| School -> "A school" // Error
“knowType”中的错误在第二种情况下:“构造函数应用于0个参数,但期望为1”。
答案 0 :(得分:6)
应该是
let knowType building =
match building with
| House -> "A house!"
| School _ -> "A school"
您需要为of School
部分提供变量。 _
只是意味着它被忽略