3 minutes, 41 seconds
Expressions, Types, and Functions
- slide 15 : 46
An example of type checking
Is the expression
(+ 1 (if (even? x) 5 "five"))
correct with respect to types?
Weak typing
It is not realized that the expression
(+ 1 "five")
is illegal.
We can imagine that it returns the erroneous value 47
Strong typing
If, for instance,
x
is 2, the expression
(+ 1 (if (even? x) 5 "five"))
is OK, and has the value 6
If
x
is odd, it is necessary to identify this as a problem which must be reported before an evaluation of the expression is attempted
Static typing
(+ 1 (if (even x) 5 "five"))
fails to pass the type check, because the type of the expression cannot be statically determined
Static type checking is rather
conservative