-
Notifications
You must be signed in to change notification settings - Fork 15
/
file.smli
105 lines (93 loc) · 3.96 KB
/
file.smli
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(*
* Licensed to Julian Hyde under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Julian Hyde licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* Tests for the file system ("file").
*)
(*) The "file" value represents the file system, starting in the current
(*) directory.
file;
> val it = {scott={},wordle={}} : {scott:{...}, wordle:{...}, ...}
(*) A subdirectory.
file.wordle;
> val it = {answers=<relation>,words=<relation>}
> : {answers:{...} list, words:{...} list, ...}
(*) Now we've gone into the directory, the type of 'file' has widened.
file;
> val it = {scott={},wordle={answers=<relation>,words=<relation>}}
> : {scott:{...}, wordle:{answers:{...} list, words:{...} list, ...}, ...}
(*) A variable via which we can access relations.
val s = file.scott;
> val s = {bonus=<relation>,dept=<relation>,emp=<relation>,salgrade=<relation>}
> : {bonus:{...} list, dept:{...} list, emp:{...} list, salgrade:{...} list,
> ...}
(*) Access two relations (emp, dept) simultaneously via a variable (s).
from d in s.dept
join e in s.emp on d.deptno = e.deptno
group e.deptno compute count
order deptno;
> val it = [{count=3,deptno=10},{count=5,deptno=20},{count=6,deptno=30}]
> : {count:int, deptno:int} list
file.scott.dept;
> val it =
> [{deptno=10,dname="ACCOUNTING",loc="NEW YORK"},
> {deptno=20,dname="RESEARCH",loc="DALLAS"},
> {deptno=30,dname="SALES",loc="CHICAGO"},
> {deptno=40,dname="OPERATIONS",loc="BOSTON"}]
> : {deptno:int, dname:string, loc:string} list
(*) Since dept is a list of records, we can query it.
from d in file.scott.dept
where d.dname elem ["ACCOUNTING", "SALES"]
compute sum of d.deptno;
> val it = 40 : int
from d in file.scott.dept
join e in file.scott.emp on d.deptno = e.deptno
group e.deptno compute count
order deptno;
> val it = [{count=3,deptno=10},{count=5,deptno=20},{count=6,deptno=30}]
> : {count:int, deptno:int} list
(*) Bonus is empty (except the line defining the fields).
val scott = file.scott;
> val scott =
> {bonus=<relation>,dept=<relation>,emp=<relation>,salgrade=<relation>}
> : {bonus:{...} list, dept:{deptno:int, dname:string, loc:string} list,
> emp:
> {comm:real, deptno:int, empno:int, ename:string, hiredate:string,
> job:string, mgrno:int, sal:real} list, salgrade:{...} list, ...}
from b in scott.bonus;
> val it = [] : {bonus:real, ename:string, job:string, sal:real} list
(*) The type of 'file' has widened further.
file;
> val it =
> {scott={bonus=<relation>,dept=<relation>,emp=<relation>,salgrade=<relation>},
> wordle={answers=<relation>,words=<relation>}}
> : {
> scott:{bonus:{bonus:real, ename:string, job:string, sal:real} list,
> dept:{deptno:int, dname:string, loc:string} list,
> emp:
> {comm:real, deptno:int, empno:int, ename:string,
> hiredate:string, job:string, mgrno:int, sal:real} list,
> salgrade:{...} list, ...},
> wordle:{answers:{...} list, words:{...} list, ...}, ...}
file.scott;
> val it = {bonus=<relation>,dept=<relation>,emp=<relation>,salgrade=<relation>}
> : {bonus:{bonus:real, ename:string, job:string, sal:real} list,
> dept:{deptno:int, dname:string, loc:string} list,
> emp:
> {comm:real, deptno:int, empno:int, ename:string, hiredate:string,
> job:string, mgrno:int, sal:real} list, salgrade:{...} list, ...}
(*) End file.smli