假设我用这种方式在OCaml中定义一个类型:
type 'a foo = My_none | Bar of 'a;;
Run Code Online (Sandbox Code Playgroud)
制作时
let a = Bar 4;;
Run Code Online (Sandbox Code Playgroud)
该Bar构造被"叫".
在下面的函数中,匹配是否调用构造函数,或者只是"识别"模式而不调用构造函数?
let get_bar x = match x with
| My_none -> failwith "None"
| Bar z -> z;;
Run Code Online (Sandbox Code Playgroud)