File: struct_pattern.sail

package info (click to toggle)
sail-ocaml 0.19.1%2Bdfsg5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,008 kB
  • sloc: ml: 75,941; ansic: 8,848; python: 1,342; exp: 560; sh: 474; makefile: 218; cpp: 36
file content (41 lines) | stat: -rw-r--r-- 791 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
default Order dec

$include <prelude.sail>

struct foo = {
    f1 : int,
    f2 : int,
    f3 : int,
}

function bar(x: foo) -> unit = {
    match x {
        struct { _ } => ()
    };
    match x {
        struct { f1 = _, f2 = _, f3 = _ } => ()
    };
    match x {
        struct { f1 = 0, f2 = _, _ } => (),
        struct { f1 = _, f2 = 0, _ } => (),
        struct { f1 = x, f2 = y, _ } => (),
    }
}

struct baz('n), 'n in {32, 64} = {
     len : int('n),
     value : bits('n),
}

function quux forall 'n, 'n == 32. (x: baz('n)) -> unit = {
    match x {
        struct { len = 32, value = _ } => ()
    }
}

function quux2 forall 'n, 'n in {32, 64}. (x: baz('n)) -> unit = {
    match x {
        struct { len = 32, value = _ } => (),
        struct { len = 64, _ } => (),
    }
}