-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.ts
85 lines (66 loc) · 1.52 KB
/
models.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Expressions
// e ::= x
// | e1 e2
// | \x -> e
// | let x = e1 in e2
export type Expression =
| VariableExpression
| ApplicationExpression
| AbstractionExpression
| LetExpression;
export interface VariableExpression {
type: 'var',
x: string,
}
export interface ApplicationExpression {
type: 'app',
e1: Expression,
e2: Expression,
}
export interface AbstractionExpression {
type: 'abs',
x: string,
e: Expression,
}
export interface LetExpression {
type: 'let',
x: string,
e1: Expression,
e2: Expression,
}
// Types
// mu ::= a
// | C mu_0 ... mu_n
// sigma ::= mu
// | Va. sigma
export type MonoType =
| TypeVariable
| TypeFunctionApplication
export type PolyType =
| MonoType
| TypeQuantifier
export type TypeFunction = "->" | "Bool" | "Int" | "List"
export interface TypeVariable {
type: 'ty-var',
a: string,
}
export interface TypeFunctionApplication {
type: 'ty-app',
C: TypeFunction,
mus: MonoType[],
}
export interface TypeQuantifier {
type: 'ty-quantifier',
a: string,
sigma: PolyType,
}
// Contexts
export const ContextMarker = Symbol()
export type Context = { [ContextMarker]: boolean, [variable: string]: PolyType }
export const makeContext = (raw: { [ContextMarker]?: boolean, [variable: string]: PolyType }): Context => {
raw[ContextMarker] = true;
return raw as Context;
}
export const isContext = (something: unknown): something is Context => {
return typeof something === "object" && something !== null && ContextMarker in something
}