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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
use derive_more::Display;
// Set layer
#[derive(Clone, Debug, PartialEq, Display)]
pub enum BuiltIn {
Nat,
Int,
Float,
Str,
Bool,
}
#[derive(Clone, Debug, PartialEq, Display)]
#[display(".{name} : {set}")]
pub struct RecordField {
pub name: String,
pub set: Set,
}
#[derive(Clone, Debug, PartialEq, Display)]
#[display("{name}. : {set}")]
pub struct VariantField {
pub name: String,
pub set: Set,
}
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Set {
#[display("{_0}")]
BuiltIn(BuiltIn),
#[display("record {{ {} }}", _0.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(" , "))]
Record(Vec<RecordField>),
#[display("variant [ {} ]", _0.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(" | "))]
Variant(Vec<VariantField>),
#[display("set({_0})")]
ClaimedSet(Instance),
#[display("{_0}")]
Var(String),
}
// Signature layer
#[derive(Clone, Debug, PartialEq, Display)]
#[display("({name} : {set})")]
pub struct Param {
pub name: String,
pub set: Set,
}
#[derive(Clone, Debug, PartialEq, Display)]
#[display(".{name} :: {signature}")]
pub struct SigField {
pub name: String,
pub signature: Signature,
}
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Signature {
#[display("Set")]
Set,
#[display("theory {{ {} }}", _0.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(" , "))]
Theory(Vec<SigField>),
#[display("{} -> {}", params.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(", "), codomain)]
Ext {
params: Vec<Param>,
codomain: Box<Signature>,
},
#[display("{_0}")]
Var(String),
}
// Element layer
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Literal {
Nat(u64),
Int(i64),
Float(f64),
Str(String),
Bool(bool),
}
#[derive(Clone, Debug, PartialEq, Display)]
#[display(".{name} = {element}")]
pub struct ElemAssign {
pub name: String,
pub element: Element,
}
#[derive(Clone, Debug, PartialEq, Display)]
#[display(".{tag} {bound} => {body}")]
pub struct CaseArm {
pub tag: String,
pub bound: String,
pub body: Element,
}
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Element {
#[display("{_0}")]
Literal(Literal),
#[display("{_0}")]
Var(String),
#[display("{{ {} }}", _0.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(" , "))]
Record(Vec<ElemAssign>),
#[display("{_0} .{_1}")]
Project(Box<Element>, String),
#[display("{_0}. {_1}")]
Inject(String, Box<Element>),
#[display("{_0} {_1}")]
App(Box<Element>, Box<Element>),
#[display("case {} of {{ {} }}", scrutinee, arms.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(" | "))]
Case {
scrutinee: Box<Element>,
arms: Vec<CaseArm>,
},
}
// Instance layer
#[derive(Clone, Debug, PartialEq, Display)]
#[display(".{name} = {instance}")]
pub struct InstAssign {
pub name: String,
pub instance: Instance,
}
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Instance {
#[display("({_0} :: Set)")]
SetCoerce(Box<Set>),
#[display("{_0}")]
Var(String),
#[display("{{ {} }}", _0.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(", "))]
Record(Vec<InstAssign>),
#[display("for {}, {body}", params.iter().map(|f| f.to_string()).collect::<Vec<_>>().join(""))]
For {
params: Vec<Param>,
body: Box<Instance>,
},
#[display("{_0} {_1}")]
App(Box<Instance>, Box<Element>),
#[display("{_0} .{_1}")]
Project(Box<Instance>, String),
}
// Declarations
#[derive(Clone, Debug, PartialEq, Display)]
pub enum Decl {
#[display("let set {name} = {set}")]
Set { name: String, set: Set },
#[display("let element {name} : {set} = {element}")]
Element {
name: String,
set: Set,
element: Element,
},
#[display("let signature {name} = {signature}")]
Signature { name: String, signature: Signature },
#[display("let instance {name} :: {signature} = {instance}")]
Instance {
name: String,
signature: Signature,
instance: Instance,
},
}
#[derive(Display)]
#[display("{}", _0.iter().map(|d| d.to_string()).collect::<Vec<_>>().join("\n"))]
pub struct Programme(pub Vec<Decl>);
|