Types 1
Table of Contents
Why Have Types?
-
prevent certain “runtime” errors
-
errors type systems help prevent
- wrong types given to primitave operators
- wrong number of arguments to a function application
- unbound identifer
- condition for if not boolean
- calling a non function
-
erros types sytesm (usually) not prevent:
- division by zero
- index out of an array
- memory leak
- reference a null pointer
- infinate loops
-
errors type systems help prevent
- readability/better documentation
- historically needed to get code to compile, we need to know how big things are
1. How type checker works
(a + b) / c
a : String
b: String
c : Int
- : string string -> String
/ : int int -> int
X: type error
f(a, b, c)
f: Int, String -> int a : int b : string c : int
X “type error”
f(a,b)
f : Int String -> Int a : Int b : String
returns Int because type checker is highly recursive
So if the return of type check is a type then pass it forward to interp