(* Code for Lecture 1 *) (* Brigitte Pientka *) (* Code for Lecture 1: Evaluation and Typing *) (* Integers *) ~1 : int; (* NOT -1 *) 4 : int; ~3+2 : int; 5 div 2 : int; (* Reals *) 3.14 : real; 5.0 / 2.0 : real; (* NOT 5 / 2 *) (* Type errors - 5 div 3.0; stdIn:1.1-1.10 Error: operator and operand don't agree [literal] operator domain: int * int operand: int * real in expression: 5 div 3.0 - 5.0 div 3; stdIn:1.1-1.10 Error: operator and operand don't agree [literal] operator domain: real * real operand: real * int in expression: 5.0 div 3 stdIn:1.5-1.8 Error: overloaded variable not defined at type symbol: div type: real - 5/3; stdIn:1.1-1.4 Error: operator and operand don't agree [literal] operator domain: real * real operand: int * int in expression: 5 / 3 - 5.0 / 3; stdIn:1.1-1.8 Error: operator and operand don't agree [literal] operator domain: real * real operand: real * int in expression: 5.0 / 3 *) (* Booleans *) true : bool; false : bool; if 0 = 0 then 1.0 else 2.0 : real; if true then 4.0 else 1.0/0.0: real; (* Type error - if 0 = 0 then 1.0 else 5 ; stdIn:1.1-1.25 Error: types of if branches do not agree [literal] then branch: real else branch: int in expression: if 0 = 0 then 1.0 else 5 *) (* Typing and Evaluation *) (* Some ill-typed expressions *) (* 2.0 + 1; if true then 1 else 2.0; true + 0; *) (* Some well-typed expressions without a value *) (* 1 div 0; if 1 div 0 = 0 then true else false; if false then 4 else 1 div 0; *)