(* Programming Languages (F28PL) lecture transcript - 20th September at 11:15 *) (* A function which returns true of the character is a number *) Char.isDigit; Char.isDigit #"5"; Char.isDigit #"0"; Char.isDigit #"9"; Char.isDigit #"a"; (* returns false *) (* A terribly vulgar function, Char.isDigit function returns a boolean, no reason for equality test *) if Char.isDigit #"2" = true then true else false; (* Import the functions from Char namespace using open *) open Char; (* Turn a char into an integer (ASCII representation) *) ord #"5"; ord #"0"; ord #"9"; (* Since we opened the Char namespace, the > operator is replaced *) 5 > 6; (* Will give a type error *) op >; (* has type char * char -> bool *) open Int; (* We can now use the > operator which takes in int * int *) op >; (* isDigit which we imported from the Char namespace is still accessible *) isDigit; (* To see what is in a structure without opening it *) signature S = INTEGER; signature S = OS; signature S = POSIX; signature S = LIST; val a = 5; (* 'a' is bound to 5 forever in this scope *) val a = 6; (* We now overwritten 'a' with another variable *) val b = a; val a = 7; (* What's in b? *) b; (* A function which returns its input *) fun identity x = x; (* Equivalent formulation *) val identity = fn x => x; (* Runs a variable to a function (square) twice *) (fun f => fn x => f(f(x))) (fn x => x*x); val poweroffour = it; poweroffour 2; poweroffour 3; (fn f => fn x => f(f(x)));