diff --git a/docs/langs/explicit-substitution/exp/Exp.cic b/docs/langs/explicit-substitution/exp/Exp.cic index 87bfc847..2e6827c9 100644 --- a/docs/langs/explicit-substitution/exp/Exp.cic +++ b/docs/langs/explicit-substitution/exp/Exp.cic @@ -1,8 +1,8 @@ datatype Exp { - var(name: String): Exp - fn(name: String, ret: Arg): Exp - ap(target: Exp, arg: Arg): Exp - let(bindings: List(Binding), body: Exp): Exp + Var(name: String): Exp + Fn(name: String, ret: Arg): Exp + Ap(target: Exp, arg: Arg): Exp + Let(bindings: List(Binding), body: Exp): Exp } class Binding { diff --git a/docs/langs/explicit-substitution/reduce/reduce.cic b/docs/langs/explicit-substitution/reduce/reduce.cic index 43e8fb87..d100e627 100644 --- a/docs/langs/explicit-substitution/reduce/reduce.cic +++ b/docs/langs/explicit-substitution/reduce/reduce.cic @@ -8,18 +8,18 @@ import { substitute } from "./substitute.cic" export function reduce(mod: Mod, exp: Exp): Exp { match (exp) { - case Exp::var(name) => match (modFind(mod, name)) { - case Maybe::just(defintion) => exp - case Maybe::nothing() => reduce(mod, defintion.exp) + case Exp::Var(name) => match (modFind(mod, name)) { + case Maybe::Just(defintion) => exp + case Maybe::Nothing() => reduce(mod, defintion.exp) } - case Exp::fn(name, ret) => - Exp::fn(exp.name, reduce(mod, ret)) + case Exp::Fn(name, ret) => + Exp::Fn(exp.name, reduce(mod, ret)) - case Exp::ap(target, arg) => + case Exp::Ap(target, arg) => doAp(mod, reduce(mod, target), reduce(mod, arg)) - case Exp::let(bindings, body) => + case Exp::Let(bindings, body) => reduce(mod, substitute(body, bindings)) } } diff --git a/docs/langs/explicit-substitution/reduce/substitute.cic b/docs/langs/explicit-substitution/reduce/substitute.cic index b87e9446..82e5619f 100644 --- a/docs/langs/explicit-substitution/reduce/substitute.cic +++ b/docs/langs/explicit-substitution/reduce/substitute.cic @@ -8,28 +8,28 @@ export function substitute( ): Exp { match (body) { case Exp::Var(name) => match (lookup(name, bindings)) { - case Maybe::just(exp) => exp - case Maybe::nothing() => body + case Maybe::Just(exp) => exp + case Maybe::Nothing() => body } - case Exp::fn(name, ret) => { + case Exp::Fn(name, ret) => { let freshName = freshen(name) - return Exp::fn( + return Exp::Fn( freshName, - Exp::let( - listAppend(bindings, [new Binding(name, Exp::var(freshName))]), + Exp::Let( + listAppend(bindings, [new Binding(name, Exp::Var(freshName))]), ret, ), ) } - case Exp::ap(target, arg) => - Exp::ap( - Exp::let(bindings, target), - Exp::let(bindings, arg), + case Exp::Ap(target, arg) => + Exp::Ap( + Exp::Let(bindings, target), + Exp::Let(bindings, arg), ) - case Exp::let(innerBindings, body) => + case Exp::Let(innerBindings, body) => substitute( listAppend(bindings, listMap(innerBindings, substituteBinding)), body,