blob: e8d1c53972641488b586d97f689fc5e5dded8994 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|