--- /dev/null
+#[derive(Clone, Debug)]
+enum Term {
+ Appl(Box<(Term, Term)>),
+ Var(usize),
+ Abst(Box<Term>),
+}
+
+impl Term {
+ fn eval(&self, e: Vec<Value>, k: Cont) -> Value {
+ match self {
+ Term::Var(v) => k.cont(e[*v].clone()),
+ Term::Abst(t) => k.cont(Value::Closure(*t.clone(), e)),
+ Term::Appl(tuple) => {
+ let (t0, t1) = *tuple.clone();
+ t0.eval(e.clone(), Cont::C2(t1, e.clone(), Box::new(k)))
+ }
+ }
+ }
+}
+
+#[derive(Clone, Debug)]
+enum Value {
+ Closure(Term, Vec<Value>),
+}
+
+impl Value {
+ fn apply(&self, v1: Value, k: Cont) -> Value {
+ match self {
+ Value::Closure(t, e) => {
+ let mut new_e = vec![v1];
+ new_e.append(e.clone().as_mut());
+ t.eval(new_e.clone(), k)
+ },
+ }
+ }
+}
+
+#[derive(Clone)]
+enum Cont {
+ C0,
+ C1(Value, Box<Cont>),
+ C2(Term, Vec<Value>, Box<Cont>)
+}
+
+impl Cont {
+ fn cont(&self, v: Value) -> Value {
+ match self {
+ Cont::C0 => v,
+ Cont::C1(v0, k) => { v0.apply(v, *k.clone()) },
+ Cont::C2(t1, e, k) => { t1.eval(e.to_vec(), Cont::C1(v, k.clone())) }
+ }
+ }
+}
+
+
+pub fn main() {
+ use Term::*;
+ println!("CEK:");
+
+ let t1: Term = Appl(Box::new((Abst(Box::new(Appl(Box::new((Var(0), Var(0)))))), (Abst(Box::new(Var(0)))))));
+ let result = t1.eval(vec![], Cont::C0);
+ println!("T1 eval: {:?}", result);
+
+ let t2: Term = Appl(Box::new((Appl(Box::new((Abst(Box::new(Var(0))), Abst(Box::new(Var(0)))))), Abst(Box::new(Var(0))))));
+ let result2 = t2.eval(vec![], Cont::C0);
+ println!("T2 eval: {:?}", result2);
+}