Skip to content

Commit

Permalink
[explicit-substitution] quit using union type, use Maybe instead
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Mar 19, 2024
1 parent b47306b commit 643b5ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/langs/explicit-substitution/reduce/lookup.cic
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Binding, Exp } from "../exp/index.cic"
export function lookup(
name: string,
bindings: List(Binding),
): Optional(Exp) {
): Maybe(Exp) {
let found = listFind(
listReverse(bindings),
(binding) => stringEqual(binding.name, name)
)

return optionalMap(found, (binding) => binding.exp)
return maybeMap(found, (binding) => binding.exp)
}
6 changes: 3 additions & 3 deletions docs/langs/explicit-substitution/reduce/reduce.cic
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { substitute } from "./substitute.cic"

export function reduce(mod: Mod, exp: Exp): Exp {
match (exp) {
case Exp::var(name) => {
let defintion = modFind(mod, name)
return if isNone(defintion) then exp else 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) =>
Expand Down
8 changes: 4 additions & 4 deletions docs/langs/explicit-substitution/reduce/substitute.cic
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export function substitute(
body: Exp,
): Exp {
match (body) {
case Exp::Var(name) => {
let found = lookup(name, bindings)
return if isNone(found) then body else found
}
case Exp::Var(name) => match (lookup(name, bindings)) {
case Maybe::just(exp) => exp
case Maybe::nothing() => body
}

case Exp::fn(name, ret) => {
let freshName = freshen(name)
Expand Down

0 comments on commit 643b5ed

Please sign in to comment.