(*warning to those with sensative ears, there is a fire alarm at 35:00 for exactly a minute*) (*a function for calculating log base 2 of an integer*) fun log2 1 = 0 | log2 n = 1 + (log2 (n div 2)); (*the forkbomb function. does not work as such however is a nice explination of the logic of a forkbomb*) fun forkbomb x = forkbomb x * forkbomb x; (*passing unit type into forkbomb function, will consume large ammounts of memory and cpu until stack reaches capacity*) (*how to make a new datatype, in this case cint*) datatype cint = CI of int * int; (*how to add cint's, please note that 'CI' shown here is a function of type 'int * int -> cint' CI is a wrapper and must be used when using cint*) fun sillyadd (CI(x,y)) = x+y; (*how not to use the sillyadd program, this gives a type error*) sillyadd (4,5); (*how to properly use the sillyadd program*) sillyadd (CI(4,5)); (*recursive loop program*) fun me x = me x; (*passing unit type into the me function this will use ~100% CPU until stopped, however uses no memory*) me (); (*making type cint, as opposed to datatype cint as done above*) type cint = int * int; (*making a natural numbers datatype*) datatype mynat = Zero | Succ of mynat; (*a function that converts integers into mynat*) fun inttomynat 0 = Zero | inttomynat n = Succ(inttomynat(n-1)); (*an example case of the usage of inttomynat*) inttomynay 5; (*making datatype present*) datatype present = Chocolate of string | Flowers of string | Cash of int; (*Cash type deconstruction*) Cash; (*making type money*) type money = int; (*passing type of money into the cash type*) Cash(9:money); (*an example of a Flowers type*) Flowers("roses") (*deconstructing the Flowers type*) Flowers; (*creating the chocolate datatype*) datatype chocolate = Choc of (string * int); (*an example of the chocolate datatype*) Choc("caramels",5); (*creating the phoneentry type*) datatype phoneentry = Assoc of (string * string); (*an example of the phoneentry type*) Assoc("Jamie","02012345678"); (*storing the previous example*) val jamiesentry = Assoc("Jamie","02012345678"); (*a function to extract the name from a phoneentry type*) fun extractname (Assoc(x,y)) = x; (*using jamiesentry with extract name*) extractname jamiesentry;