Skip to content

Commit d90ae25

Browse files
committed
add Value postfix to value types
1 parent e7464ee commit d90ae25

10 files changed

Lines changed: 39 additions & 34 deletions

File tree

‎TODO.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
> back to call-by-value evaluation
22
3-
add Value postfix to value types
43
extract definition/
5-
64
rename bind to binding
7-
rename Values.Lambda to Value.Closure
85

96
remove Lazy
107
remove DelayedApply

‎src/lang/equal/equalInCtx.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export function equalInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
4444

4545
const freshName = freshen(ctx.boundNames, lhs.name)
4646
ctx = ctxBindName(ctx, freshName)
47-
const v = Neutrals.Var(freshName)
48-
const arg = Values.NotYet(v)
47+
const v = Neutrals.VarNeutral(freshName)
48+
const arg = Values.NotYetValue(v)
4949
return equalInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
5050
}
5151

@@ -60,8 +60,8 @@ export function equalInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
6060

6161
const freshName = freshen(ctx.boundNames, rhs.name)
6262
ctx = ctxBindName(ctx, freshName)
63-
const v = Neutrals.Var(freshName)
64-
const arg = Values.NotYet(v)
63+
const v = Neutrals.VarNeutral(freshName)
64+
const arg = Values.NotYetValue(v)
6565
return equalInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
6666
}
6767

‎src/lang/evaluate/evaluateWithDelay.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export function evaluateWithDelay(mod: Mod, env: Env, exp: Exp): Value {
2222
}
2323

2424
case "Lambda": {
25-
return Values.Lambda(mod, env, exp.name, exp.ret)
25+
return Values.LambdaValue(mod, env, exp.name, exp.ret)
2626
}
2727

2828
case "Apply": {
2929
const target = evaluateWithDelay(mod, env, exp.target)
3030
const arg = evaluateWithDelay(mod, env, exp.arg)
3131
// const arg = Values.Lazy(mod, env, exp.arg)
32-
return Values.DelayedApply(target, arg)
32+
return Values.DelayedApplyValue(target, arg)
3333
}
3434

3535
case "Let": {
@@ -50,7 +50,7 @@ export function evaluateWithDelay(mod: Mod, env: Env, exp: Exp): Value {
5050
export function applyWithDelay(target: Value, arg: Value): Value {
5151
switch (target.kind) {
5252
case "NotYet": {
53-
return Values.NotYet(Neutrals.Apply(target.neutral, arg))
53+
return Values.NotYetValue(Neutrals.ApplyNeutral(target.neutral, arg))
5454
}
5555

5656
case "Lambda": {

‎src/lang/readback/readbackInCtx.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function readbackInCtx(ctx: Ctx, value: Value): Exp {
3434

3535
const freshName = freshen(ctx.boundNames, value.name)
3636
ctx = ctxBindName(ctx, freshName)
37-
const arg = Values.NotYet(Neutrals.Var(freshName))
37+
const arg = Values.NotYetValue(Neutrals.VarNeutral(freshName))
3838
const ret = applyWithDelay(value, arg)
3939
return Exps.Lambda(freshName, readbackInCtx(ctx, ret))
4040
}

‎src/lang/same/sameInCtx.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export function sameInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
4141
if (lhs.kind === "Lambda" && !lambdaIsDefined(lhs)) {
4242
const freshName = freshen(ctx.boundNames, lhs.name)
4343
ctx = ctxBindName(ctx, freshName)
44-
const arg = Values.NotYet(Neutrals.Var(freshName))
44+
const arg = Values.NotYetValue(Neutrals.VarNeutral(freshName))
4545
return sameInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
4646
}
4747

4848
if (rhs.kind === "Lambda" && !lambdaIsDefined(rhs)) {
4949
const freshName = freshen(ctx.boundNames, rhs.name)
5050
ctx = ctxBindName(ctx, freshName)
51-
const arg = Values.NotYet(Neutrals.Var(freshName))
51+
const arg = Values.NotYetValue(Neutrals.VarNeutral(freshName))
5252
return sameInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
5353
}
5454

‎src/lang/value/Neutral.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { type Value } from "../value/index.ts"
22

3-
export type Neutral = Var | Apply
4-
export type Var = { kind: "Var"; name: string }
5-
export type Apply = { kind: "Apply"; target: Neutral; arg: Value }
3+
export type Neutral = VarNeutral | ApplyNeutral
4+
export type VarNeutral = { kind: "Var"; name: string }
5+
export type ApplyNeutral = { kind: "Apply"; target: Neutral; arg: Value }
66

7-
export function Var(name: string): Var {
7+
export function VarNeutral(name: string): VarNeutral {
88
return {
99
kind: "Var",
1010
name,
1111
}
1212
}
1313

14-
export function Apply(target: Neutral, arg: Value): Apply {
14+
export function ApplyNeutral(target: Neutral, arg: Value): ApplyNeutral {
1515
return {
1616
kind: "Apply",
1717
target,

‎src/lang/value/Value.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { type Exp } from "../exp/index.ts"
33
import { type Mod } from "../mod/index.ts"
44
import { type Neutral } from "../value/index.ts"
55

6-
export type Value = NotYet | Lambda | Lazy | DelayedApply
6+
export type Value = NotYetValue | ClosureValue | LazyValue | DelayedApplyValue
77

8-
export type NotYet = {
8+
export type NotYetValue = {
99
kind: "NotYet"
1010
neutral: Neutral
1111
}
1212

13-
export type Lambda = {
13+
export type ClosureValue = {
1414
kind: "Lambda"
1515
mod: Mod
1616
env: Env
@@ -19,28 +19,33 @@ export type Lambda = {
1919
definedName?: string
2020
}
2121

22-
export type Lazy = {
22+
export type LazyValue = {
2323
kind: "Lazy"
2424
mod: Mod
2525
env: Env
2626
exp: Exp
2727
value?: Value
2828
}
2929

30-
export type DelayedApply = {
30+
export type DelayedApplyValue = {
3131
kind: "DelayedApply"
3232
target: Value
3333
arg: Value
3434
}
3535

36-
export function NotYet(neutral: Neutral): NotYet {
36+
export function NotYetValue(neutral: Neutral): NotYetValue {
3737
return {
3838
kind: "NotYet",
3939
neutral,
4040
}
4141
}
4242

43-
export function Lambda(mod: Mod, env: Env, name: string, ret: Exp): Lambda {
43+
export function LambdaValue(
44+
mod: Mod,
45+
env: Env,
46+
name: string,
47+
ret: Exp,
48+
): ClosureValue {
4449
return {
4550
kind: "Lambda",
4651
mod,
@@ -50,7 +55,7 @@ export function Lambda(mod: Mod, env: Env, name: string, ret: Exp): Lambda {
5055
}
5156
}
5257

53-
export function Lazy(mod: Mod, env: Env, exp: Exp): Lazy {
58+
export function LazyValue(mod: Mod, env: Env, exp: Exp): LazyValue {
5459
return {
5560
kind: "Lazy",
5661
mod,
@@ -59,7 +64,10 @@ export function Lazy(mod: Mod, env: Env, exp: Exp): Lazy {
5964
}
6065
}
6166

62-
export function DelayedApply(target: Value, arg: Value): DelayedApply {
67+
export function DelayedApplyValue(
68+
target: Value,
69+
arg: Value,
70+
): DelayedApplyValue {
6371
return {
6472
kind: "DelayedApply",
6573
target,

‎src/lang/value/delayedApplyUtils.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { DelayedApply, type Value } from "./Value.ts"
1+
import { DelayedApplyValue, type Value } from "./Value.ts"
22

3-
export function delayedApplyHead(delayedApply: DelayedApply): Value {
3+
export function delayedApplyHead(delayedApply: DelayedApplyValue): Value {
44
if (delayedApply.target.kind === "DelayedApply") {
55
return delayedApplyHead(delayedApply.target)
66
}

‎src/lang/value/lambdaUtils.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { type Lambda } from "./Value.ts"
1+
import { type ClosureValue } from "./Value.ts"
22

3-
export type DefinedLambda = Lambda & { definedName: string }
3+
export type DefinedLambda = ClosureValue & { definedName: string }
44

5-
export function lambdaIsDefined(lambda: Lambda): lambda is DefinedLambda {
5+
export function lambdaIsDefined(lambda: ClosureValue): lambda is DefinedLambda {
66
return lambda.definedName !== undefined
77
}
88

9-
export function lambdaSameDefined(x: Lambda, y: Lambda): boolean {
9+
export function lambdaSameDefined(x: ClosureValue, y: ClosureValue): boolean {
1010
return (
1111
lambdaIsDefined(x) &&
1212
lambdaIsDefined(y) &&

‎src/lang/value/lazyUtils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { evaluate } from "../evaluate/index.ts"
22
import type * as Values from "./index.ts"
33
import { type Value } from "./index.ts"
44

5-
export function lazyActive(lazy: Values.Lazy): Value {
5+
export function lazyActive(lazy: Values.LazyValue): Value {
66
if (lazy.value !== undefined) {
77
return lazy.value
88
}

0 commit comments

Comments
 (0)