(* Source code for lecture 2: Types *) (* Bindings *) type studentnumber = int type name = string type class = string type grade = char val id : studentnumber = 200242 val joe : name = "Joe Smith" val jc : class = "CS201" val jg : grade = #"A" (* Type of Intergers *) (* Values *) val pos10 : int = 10 val pos5 : int = 5 val neg42 : int = ~42 (* Operations *) val result1 : int = 10 + pos5 val result2 : int = 5 * 4 * 3 * 2 * 1 (* Type of Reals *) (* Values *) val approxpi : real = 3.141 (* Operations *) val result3 : real = Math.sin (approxpi / 2.0) (* Type of Booleans *) (* Values *) val booltrue : bool = true (* Operations *) val result4 : int = if 10 < 15 then 1 else ~1 val result5 : bool = 12 < 15 (* Type of String *) (* Values *) val s1 = "Hello World" val s2 = "Computer Science" (*Operations*) val result6 : bool = s1 < s2 (* Type of functions *) (* Values *) val f1 : real -> real = fn x:real => (Math.sin x * Math.sin x) + (Math.cos x * Math.cos x) val f2 : string -> int = fn s:string => size s (* Operations *) val result7 : real = f1 10.0 val result8 : int = f2 "Carsten"