File: list_torture.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 (58 lines) | stat: -rw-r--r-- 1,445 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
52
53
54
55
56
57
58
default Order dec

$include <prelude.sail>

union exception = {
  Exc_list_string : list(string),
  Exc_list_int : list(int),
}

val list_length : forall ('a : Type). list('a) -> int

function list_length(xs) = match xs {
  x :: xs => 1 + list_length(xs),
  [||] => 0,
}

val my_cons : forall ('a : Type). ('a, list('a)) -> list('a)

val my_cons_n : forall 'n 'm, 'n >= 32 & 'n == 'm. (int('n), list(int('m))) -> list(int('m))

val specialized_cons : forall 'n, 'n == 32. (int('n), list(int('n))) -> list(int('n))

function my_cons(x, xs) = x :: xs

function my_cons_n(x, xs) = x :: xs

function specialized_cons(x, xs) = x :: xs

val hd_or_zero : list(int) -> int

function hd_or_zero(xs) = match xs {
  x :: xs => x,
  [||] => 0,
}

let toplevel_list : list(string) = [|"hello", "world"|]

val main : unit -> unit

function main() = {
    let xs: list(int) = my_cons(1, 2 :: my_cons(3, [|4|]));
    let ys = xs;
    var zs = xs;
    zs = 5 :: ys;
    print_int("hd_or_zero(zs) = ", hd_or_zero(zs));
    let xs = my_cons_n(32, [|32, 32, 32|]);
    var ws = specialized_cons(32, [|32|]);
    ws = xs;
    print_int("list_length(xs) = ", list_length(xs));
    print_int("list_length(ys) = ", list_length(ys));
    print_int("list_length(zs) = ", list_length(zs));
    try throw Exc_list_int(xs) catch {
      Exc_list_int(x :: _) => print_int("32 == ", x),
      Exc_list_string(_ :: _) => assert(false),
      _ => assert(false),
    };
    ()
}