(*a demonstration of how to reverse a string*) (implode o rev o explode) "Hello"; (*an alternate way of reversing a string*) (fn x => implode(rev(explode(x)))) "Hello"; (*the 'true' element in type bool*) true; (*essentially an ML way of expressing (true AND false), naturally returning false*) false andalso true; (*the factorial function*) fun fact 0 = 1 | fact n = n*(fact (n-1)); (*factorial of 5000, note that this gives a rediculously sized number (most likely inaccurate too)*) fact 5000; (*a delay occurs when we enter 50000*) fact 50000; (*checking if factorial 40000 and factorial 40000 are the same (you may want to change these figures depending on the computing power of your machine)*) (fact 40000) = (fact 40000); (*a combination of the previous example and the 'false andalso true;' function*) ((fact 50000) = (fact 50000)) andalso false; (*essentially the same as the previous example but with the statements switched*) false andalso ((fact 50000) = (fact 50000)); (*a not 'in fix' function using the unit type (not examinable)*) fun alexand x y =(x ()) andalso (y ()); (*hello unit!*) (*feeding a previous example *) alexand (fn x => false) (fn x => ((fact 50000) = (fact 50000))); (*duplicates a list n number of times and then returns a list of said duplicates*) fun nduplicate 0 x = [] | nduplicate n x = x::(nduplicate (n-1) x); (*dulicate of factorial 50 of the given string (adjust the numbers in the following functions to suit your hardware)*) nduplicate (fact 50) "All work and no play makes Jack a dull boy"; (*duplicatates the factorial function factorial 50 times*) nduplicate (fact 50) fact; (*applies the factorial function to a duplicated lise ,note that 'map' simply iterates across the list*) map fact(nduplicate (fact 50) 50000); (*explodes all string in the list*) map explode ["Table","Chair","Person","","Void"]; (*same as before with the addded step of reversing the list after explosion*) map rev (map explode ["Table","Chair","Person","","Void"]); (*same as before but converts the char list back into a string list*) map implode (map rev (map explode ["Table","Chair","Person","","Void"])); (*combines a list of strings into one string*) fun stringlistimplode [] = "" | stringlistimplode (h::t) = h ^ (stringlistimplode t); (*same as before but concatenates the string list together into a single string*) stringlistimplode (map implode (map rev (map explode ["Table","Chair","Person","","Void"]))); (*same as the previous example but with the o operator*) (stringlistimplode o (map implode) o (map rev) o (map explode)) ["Table","Chair","Person","","Void"]; (*how to make your own type, a custom type is made up of types that already exist*) type phoneentry = string * string; (*an example of a phoneentry type*) ("Jamie", "02012345678") : phoneentry; (*making a phonebook from the phoneentry type*) type phonebook = phoneentry list; (*making a phonebook*) [("Jamie", "02012345678")] : phonebook; (*a datatype is made up of types that are uniquely defined in the datatype itself*) datatype mybool = myfalse | mytrue (*a tree made using data*) datatype mytree = leaf | node of int * mytree *mytree; (*an example of said tree*) node(5,leaf,leaf);