(* Programming Languages (F28PL) lecture transcript - 4th October at 11:15 *) Char.succ; (* has type char -> char *) val incrementstring = implode o (map Char.succ) o explode; incrementstring "HAL"; (* returns "IBM" *) implode; (* has type char list -> string *) map Char.succ; (* has type char list -> char list *) explode; (* has type string -> char list *) op =; (* takes in two equality types (alpha primed) *) (fn x => x*x) 5; (* Our sumlist function *) fun sumlisth s [] = s | sumlisth s (h::t) = sumlisth (s+h) t; fun sumlist l = sumlisth 0 l; (* A function which creates a big list *) fun gigantalist 0 = [1] | gigantalist n = (gigantalist (n-1))@[n*n*n*n]@(gigantalist (n-1)); gigantalist 16; length (gigantalist 16); val mylist = gigatalist 20; sumlist mylist; (* A *hopefully* faster sumlist function *) fun sumlistr [] = 0 | sumlistr (h::t) = h + (sumlistr t); (* Functions from http://www.macs.hw.ac.uk/~gabbay/F28PL/notes/tail-recursion.ml *) fun factr 0 = 1 | factr n = n*(factr (n-1)); fun facth c 0 = c | facth c n = facth (n*c) (n-1); fun fact n = facth 1 n; factr 10; factr 30; (* overflow raised exception *) factr 20; fun sumto f 0 = 0.0 | sumto f n = (f n) + (sumto f (n-1)); sumto (fn x => real x) 10;