Skip to content

Commit

Permalink
[explicit-substitution] type constructor should use PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Mar 20, 2024
1 parent 643b5ed commit 860a0da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions docs/langs/explicit-substitution/exp/Exp.cic
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions docs/langs/explicit-substitution/reduce/reduce.cic
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
22 changes: 11 additions & 11 deletions docs/langs/explicit-substitution/reduce/substitute.cic
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 860a0da

Please sign in to comment.