-
Notifications
You must be signed in to change notification settings - Fork 1
/
typechecker.ts
41 lines (39 loc) · 1.09 KB
/
typechecker.ts
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
import { Term } from "./parser.ts";
import { lookupInStdLib } from "./stdlib.ts";
import { assertNever } from "./utils.ts";
export type Type =
| { tag: "TyBool" }
| { tag: "TyInt" }
| { tag: "TyStr" }
// | { tag: "TyList"; elementType: Type }
| { tag: "TyArrow"; paramTypes: Type[]; returnType: Type };
export function typeCheck(term: Term): Type {
switch (term.tag) {
case "TmBool":
throw new Error("TODO");
case "TmInt":
throw new Error("TODO");
case "TmStr":
throw new Error("TODO");
case "TmVar":
throw new Error("TODO");
case "TmIf": {
// { tag: "TmIf"; cond: Term; then: Term; else: Term }
throw new Error("TODO");
}
case "TmLet": {
// { tag: "TmLet"; name: string; val: Term; body: Term }
throw new Error("TODO");
}
case "TmAbs": {
// { tag: "TmAbs"; params: { name: string; typeAnn: Type }[]; body: Term }
throw new Error("TODO");
}
case "TmApp": {
// { tag: "TmApp"; func: Term; args: Term[] }
throw new Error("TODO");
}
default:
return assertNever(term);
}
}