-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtraverse.cue
42 lines (36 loc) · 1.44 KB
/
traverse.cue
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
package thema
// SearchAndValidate is a pseudofunction that takes a lineage (lin) and some candidate
// data (inst) as an argument, and searches the lineage for a schema against which
// that data is valid.
//
// A #LinkedInstance is "returned" (out) corresponding to the first schema in the
// lineage for which the data is a valid instance of the schema. Data is not checked
// for concreteness. If there is no match, bottom is returned.
//
// TODO optionally check for concreteness of otherwise valid data
// TODO functionize
#SearchAndValidate: fn={
lin: _
inst: {...} // TODO consistently rename to 'object' or something
out: #LinkedInstance
out: [ for _, sch in fn.lin.schemas if ((inst & sch._#schema) != _|_) {
v: sch.version
lin: fn.lin
inst: inst & sch._#schema
}, _|_][0]
}
#ValidFor: {
lin: _
inst: {...} // TODO consistently rename to 'object' or something
out: #SyntacticVersion
out: [ for _, sch in lin.schemas if ((sch._#schema & inst) != _|_) {sch.version}][0]
}
// #LinkedInstance represents data that is an instance of some schema, the
// version of that schema, and the lineage of the schema.
#LinkedInstance: {
inst: {...} // TODO consistently rename to 'object' or something
lin: #Lineage & {_atLeastOneSchema: true}
v: #SyntacticVersion // TODO rename to 'version'
// TODO need proper validation/subsumption check here, not simple unification
// _valid: inst & (#Pick & {lin: L.lin, v: v}).out
}