-
Notifications
You must be signed in to change notification settings - Fork 1
Type Checking
lakahsara edited this page Dec 22, 2017
·
7 revisions
The type checker is to determine if the program is well-typed or not.
- It takes the AST generated from the parser.
- update the environment each time we define a new variable or function.
- generate a list of typing equations that should hold for our term to be well typed.
We do recursive traversal of the AST and generate the equivalent equation, and when we have a Var type the
typing is done relative to the typing environment that map between identifiers and its type.
Then we check the correctness for each equation to determine if our program is well typed or not.
If it's not well typed we throw a failwith exception with the right error message.
Initially, the environment contains the types of the predefined function ("print_int", "print_float")
.