File: gh1481.ml

package info (click to toggle)
js-of-ocaml 5.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,020 kB
  • sloc: ml: 91,250; javascript: 57,289; ansic: 315; makefile: 271; lisp: 23; sh: 6; perl: 4
file content (51 lines) | stat: -rw-r--r-- 971 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
let%expect_test _ =
  let prog =
    {|
type test = [ `B | `C | `D | `A ]

let to_string (tag : test) =
  match tag with
  | `A -> ("`A")
  | `B -> ("`B")
  | `C -> ("`C")
  | `D -> ("`D")

let correct x y =
  let z =
    match x, y with
    | (`A, v) | (v, `A) -> v
    | `B, _ | _, `B -> `B
    | `C, _ | _, `C -> `C
    | `D, `D -> `D
  in
  z

let incorrect x y =
  match x, y with
  | (`A, v) | (v, `A) -> v
  | `B, _ | _, `B -> `B
  | `C, _ | _, `C -> `C
  | `D, `D -> `D

let () =
  let a = `C in
  Printf.printf "[a] is: %s\n" (to_string a);

  let b = `A in
  Printf.printf "[b] is: %s\n" (to_string b);

  let c = correct a b in
  Printf.printf "[correct a b] is: %s\n" (to_string c);

  let d = incorrect a b in
  Printf.printf "[incorrect a b] is: %s\n" (to_string d);

  |}
  in
  Util.compile_and_run ~debug:false ~flags:[ "--disable"; "inline" ] prog;
  [%expect
    {|
    [a] is: `C
    [b] is: `A
    [correct a b] is: `C
    [incorrect a b] is: `C |}]