我正在尝试使用模式匹配来编写计算器应用程序.
两种主要类型定义如下:
type key = Plus | Minus | Multi | Div | Equals | Digit of int;;
type state = {
lcd: int; (* last computation done *)
lka: key; (* last key actived *)
loa: key; (* last operation actived *)
vpr: int (* value print on the screen *)
};;
let print_state s =
match s with
state (a,_,_,d) -> print_int a; //Here has the compile error
print_newline();
print_int d;
print_newline();;
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个像这样的州:
let initial_state = { lcd=0; …
Run Code Online (Sandbox Code Playgroud)