相关疑难解决方法(0)

在Ocaml中记录类型模式匹配

我正在尝试使用模式匹配来编写计算器应用程序.

两种主要类型定义如下:

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)

ocaml types record pattern-matching

15
推荐指数
1
解决办法
9388
查看次数

标签 统计

ocaml ×1

pattern-matching ×1

record ×1

types ×1