(*an example of exception handling, returns 3 since Div is handled by returning 3*) 0 div 0 handle Div => 3; (*variable x of type int ref that points to the integer 5*) val x = ref 5; (*sets x to be a pointer to 56*) x := 56; (*a pointer assignment function*) fun myassign y = x := y; (*an example of using the previous example, also shows x afterward*) myassign 42; x; (*assigns x twice*) (myasssign 1, myassign 2); (*what will this return?? ref 1 or ref 2??*) x; (*and what about this????*) (myassign 3,myassign 4,x); (*hello world program*) print "hello world\n"; (*compares the print function to a unit type (returns true)*) (print "hello world\n") = (); (*how to access the Math library power function*) Math.pow; (*how to use the inifinte integer power function*) IntInf.pow(2,9000); (*warning, large number*) (*gives a type error*) Math.pow(2,9000); (*Too big, just returns infinite*) Math.pow(2.0,9000.0); (*this one works fine*) Math.pow(2.0,900.0); (*opens the Math library, this lets you see the functions that can be used with the 'Math.' signage*) open Math; (*sets the 'II' signage to the IntInf Library*) structure II = IntInf; (*sets the 'M' signage to the Math library*) structure M = Math; (*deconstructing the functions with the same name in the libraries*) II.pow; M.pow; (*extending the print depth to 100 (notice the pointer usage)*) PolyML.Compiler.printDepth := 100; (*printing all the current loaded structures*) PolyML.Compiler.structureNames(); (*opening random structures*) open PackWord32Little; open weak; open time; (*since there wasn't much code in this one I'll also put the ML code from lecture 11 in here for the sake of completeionism.*) (*making the simple datatype*) datatype simple = S of int; (*making a simple type with an int 5*) S 5; (*function for converting a simple type to an int type*) fun simpletoint (S x) = x; (*creating a simple type variable*) val simplevalue = S 5; (*using the simpletoint function on the simplevalue variable, this returns 5*) simpletoint simplevalue; (*making the binary tree type*) datatype bt = N of (bt*bt) | L of int; (*making a function that sums the contents of a tree*) fun sumbt (L i) = i | sumbt (N (x,y)) = (sumbt x) + (sumbt y); (*using sumbt on a tree*) sumbt (N(L 5,L 6)); (* Good luck with the coursework guys! - Cameron *)