我正在尝试使用模式匹配来编写一个计算器应用程序。
以下是定义的两种主要类型:
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();;
然而,如果我的状态是这样的:
let initial_state = { lcd=0; lka=Equals; loa=Equals; vpr=0 } ;;
那么当我调用这个函数时:
print_state initial_state;;
它将会有编译错误。有人可以告诉我编译失败的原因吗?谢谢。
Error: Syntax error
unexpected token "("