1: #line 1271 "./lpsrc/flx_tutorial.pak"
2:
3: union list[T] =
4: | Cons of T * list[T]
5: | Empty
6: ;
7:
8: struct pair[T,U] =
9: {
10: fst : T;
11: snd : U;
12: }
13:
14: var x = Cons (1,Empty[int]);
15:
16:
17: x = Cons(2,x);
18: x = Cons(3,x);
19:
20: fun f[t] (x:list[t]):list[t] = { return x; }
21:
22: x = f(x);
23:
24: val y = pair(1,2);
25: print y.fst; print ","; print y.snd; endl;
26:
27:
28:
29:
30: module F[T] {
31: fun id1(x:T):T = { return x; }
32: }
33:
34: print (F[int]::id1 1); endl;
35:
36: module A[T] {
37: module B[U] {
38: fun id2[V](x:T,y:U,z:V):V*U*T = { return z,y,x; }
39: }
40: }
41:
42: val zyx = (A[int]::B[int]::id2(1,2,3));
43: print zyx.(0);
44: print zyx.(1);
45: print zyx.(2);
46: endl;
47:
48:
49: fun idt[T] (x:T):T*T = { return x,x; }
50: fun idt[T] (x:T*T):T*T = { return x; }
51:
52: val x1 = idt(1);
53: val x2 = idt(1,2);
54: print x1.(0); print x1.(1); endl;
55: print x2.(0); print x2.(1); endl;
56:
57: proc pr[T] (x:list[T], pp:T->void) {
58: match x with
59: | Cons (?i,?t) => { pp i; pr (t,pp); }
60: | Empty => { print "Empty"; }
61: endmatch
62: ;
63: }
64:
65: proc printint (x:int) { print x; }
66:
67:
68: pr (x,(printint of (int))); endl;
69: