diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-08-03 09:18:06 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-08-03 09:18:06 -0700 |
| commit | fc2844ae88c85f082b47630b92a55bca3ff285b1 (patch) | |
| tree | 4a6cca7892459ece38bf72b61352d4fc1bb239e0 /gock.ts | |
| download | gock-fc2844ae88c85f082b47630b92a55bca3ff285b1.tar.gz gock-fc2844ae88c85f082b47630b92a55bca3ff285b1.zip | |
Init
Diffstat (limited to 'gock.ts')
| -rw-r--r-- | gock.ts | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,42 @@ +type Int = "Int"; +type Bool = "Bool"; +type Atom = Int | Bool; +type SimpleType = Arrow | Atom; +type Arrow = { + left: SimpleType; + right: SimpleType; +}; + +type Identifier = string; + +type Binding = { + name: Identifier; + type?: SimpleType; +}; + +type Abstraction = { + binding: Binding; + body: ASTNode; +}; + +type ASTNode = Abstraction | Application | Identifier; + +// + +class Environment<T> { + constructor(private readonly _captures: Map<Identifier, T>, private readonly _parent?: Environment) {} + + public add(identifier: Identifier, substitution: T): Environment<T> { + const captures = new HashMap(); captures.put(identifier, substitution); + return new Environment<>(captures, this); + } + + public get(identifier: Identifier): T? { + if (this._captures.has(identifier)) return this._captures.get(identifier); + return this._parent?.get(identifier); + } +} + +//const tokenize +// const parse +// const check |
