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
use voile_util::{
level::Level,
loc::Ident,
meta::MI,
tags::VarRec,
uid::{DBI, GI, UID},
};
use crate::syntax::{
common,
common::ConHead,
core::subst::{RedEx, Subst},
};
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ValData {
pub kind: VarRec,
pub def: GI,
pub args: Vec<Term>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Val {
Type(Level),
Data(ValData),
Pi(Bind<Box<Term>>, Closure),
Cons(ConHead, Vec<Term>),
Meta(MI, Vec<Elim>),
Axiom(UID),
Var(DBI, Vec<Elim>),
Id(Box<Term>, Box<Term>, Box<Term>),
Refl,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Term {
Whnf(Val),
Redex(GI, Ident, Vec<Elim>),
}
pub type Bind<T = Term> = common::Bind<T>;
pub type Let<T = Term> = common::Let<T>;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Elim {
App(Box<Term>),
Proj(String),
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Closure {
Plain(Box<Term>),
}
impl Closure {
pub fn instantiate(self, arg: Term) -> Term {
self.instantiate_safe(arg)
.unwrap_or_else(|e| panic!("Cannot split on `{}`.", e))
}
pub fn instantiate_safe(self, arg: Term) -> Result<Term, Term> {
let Closure::Plain(body) = self;
Ok(body.reduce_dbi(Subst::one(arg)))
}
}