1.1 Array constructors.
begin
val x2 = (3, 4);
print$ x2.0;
print$ x2.1;
endl;
val x3 = (5, 6, 7);
print$ x3.0;
print$ x3.1;
print$ x3.2;
endl;
val x4 = (8, 9, 10, 11);
print$ x4.0;
print$ x4.1;
print$ x4.2;
print$ x4.3;
endl;
end
34
567
891011
1.2 Array component fetch
begin
val x2 = (3, 4);
print$ x2.0;
print$ x2.1;
endl;
val x3 = (5, 6, 7);
print$ x3.0;
print$ x3.1;
print$ x3.2;
endl;
val x4 = (8, 9, 10, 11);
print$ x4.0;
print$ x4.1;
print$ x4.2;
print$ x4.3;
endl;
end
34
567
891011
1.3 Array length len
begin
print$ len$ (5, 6); endl;
print$ len$ (7, 8, 9); endl;
print$ len$ (7, 8, 9, 10); endl;
end
2
3
4
1.4 Array component fetch
begin
val x2 = (5, 6);
print$ x2.0;
print$ x2.1;
endl;
val x3 = (7, 8, 9);
print$ x3.0;
print$ x3.1;
print$ x3.2;
endl;
val x4 = (10, 11, 12, 13);
print$ x4.0;
print$ x4.1;
print$ x4.2;
print$ x4.3;
endl;
end
56
789
10111213
1.5 Array iter
.
begin
val f = proc (i:int) { print i; };
iter f$ (4, 5); endl;
iter f$ (4, 5, 6); endl;
iter f$ (4, 5, 6, 7); endl;
end
45
456
4567
1.6 Array map
.
begin
val f = proc (i:int) { print i; };
val g = fun (i:int) => i - 1;
iter f$ map g$ (4, 5); endl;
iter f$ map g$ (4, 5, 6); endl;
iter f$ map g$ (4, 5, 6, 7); endl;
end
34
345
3456
1.7 Array fold_left
.
begin
val f = fun (x:int) (y:int) => x - y;
print$ fold_left f 3$ (4, 5); endl;
print$ fold_left f 3$ (4, 5, 6); endl;
print$ fold_left f 3$ (4, 5, 6, 7); endl;
end
-6
-12
-19
1.8 Array fold_right
.
begin
val f = fun (x:int) (y:int) => x - y;
print$ fold_right f (4, 5) 6; endl;
print$ fold_right f (4, 5, 6) 7; endl;
print$ fold_right f (4, 5, 6, 7) 8; endl;
end
5
-2
6
1.9 Composed HOFs rev
and iter
.
begin
val f = proc (i:int) { print i; };
iter f$ rev$ (4, 5); endl;
iter f$ rev$ (4, 5, 6); endl;
iter f$ rev$ (4, 5, 6, 7); endl;
end
54
654
7654
1.10 Composed HOFs map
and iter
.
begin
val f = proc (i:int) { print i; };
val g = fun (i:int) => i - 1;
iter f$ map g$ (4, 5); endl;
iter f$ map g$ (4, 5, 6); endl;
iter f$ map g$ (4, 5, 6, 7); endl;
end
34
345
3456
1.11 Array fold_left
.
begin
val f = fun (x:int) (y:int) => x - y;
print$ fold_left f 3$ (4, 5); endl;
print$ fold_left f 3$ (4, 5, 6); endl;
print$ fold_left f 3$ (4, 5, 6, 7); endl;
end
-6
-12
-19
1.12 Array fold_right
.
begin
val f = fun (x:int) (y:int) => x - y;
print$ fold_right f (4, 5) 6; endl;
print$ fold_right f (4, 5, 6) 7; endl;
print$ fold_right f (4, 5, 6, 7) 8; endl;
end
5
-2
6
1.13 Composed HOFs iter
and rev
.
begin
val f = proc (i:int) { print i; };
iter f$ rev$ (4, 5); endl;
iter f$ rev$ (4, 5, 6); endl;
iter f$ rev$ (4, 5, 6, 7); endl;
end
54
654
7654