(*the add operator*) op +; (*a tuple of (int,int)*) (2,3); (*the multiply function *) op *; (*multi operator on it's own, produces a warning*) *; (*example of a boolean inequality, returns false*) 5=6; (*example of a false boolean equality, returns false*) true=false; (*compares the x and y values, returns true if they are the same*) fn (x,y) => x=y; (*same as the previous example, however specifies integer input values*) val myinteq = fn((x:int),y) => x=y; (*compares 5 and 5, returns true*) myinteq (5,5); (*compares 5 and 6.0, gives an error as these are different types*) myinteq(5,6.0); (*describes the 'real' function, which converts real types to int types*) real; (*same as the previous comparing function, however compares an int and a real and doesn't break, this crashes since reals can not an equality type*) val myintrealeq = fn (x,y)) => (real x) = y; (*with less sugar, still gives an error*) val myintrealeq = fn((x:int),(y:real)) => (real x) = y; (*comparing reals,returns an error since reals are not a equality type*) 0.0 = 0.0; (*demonstrates that Strings are an equality type, returns false as these are subtly different*) "Hello World" = "Hello world"; (*a hacky way for finding equality in reals using ad hoc polymorphism*) val myintrealeq = fn ((x:real),(y:real)) => x>=y andalso y<=x; (*compares the two reals and returns false as they are not the same, on the plus side however, does not give an error*) myintrealeq(0.0,0.1); (*a low sugar function for comparing elements of type real*) (op >=):((real * real)->bool); (*a low sugar function for comparing elements of type int*) (op >=):((int * int)->bool); (*examples of elements of type char*) #"a"; #"A"; #"b"; (*a low sugar function for comparing char types*) (op >=):((char * char)->bool); (*a low sugar function for comparing string types*) (op >=):((string * string)->bool); (*compares a string and a char, gives a type error*) #"a" >= "a"; (*a demonstration that negative numbers require a curly minus sign*) 1 >= ~2; (*a demonstration of the greater than function*) op >; (*compares equal chars, returns true as they are such*) #"a" >= #"a"; (*compares chars that are different to each other, returns false since #"a" is not greater than #"b" on the ASCII table*) #"a" >= #"b"; (*shockingly, #"A" is not greater than #"a"*) #"A" >= #"a"; (*even more controversially, this statement returns true*) #"z" > #"A"; (*now get this: This statement is true. Please note that these are strings*) "aardvark" > "Zulu"; (*a non-named function for adding elements of type int*) fn (x,y) => x+y; (*a named function for adding elements of type int, like the previous one only can be called again*) val myadd = fn (x,y) => x+y; (*a more sugared version of the previous example*) fun myadd (x,y) = x+y; (*stores the value fed in, then awaits the user to enter a further int for y, brackets here are merely for clarity*) val myadd2 = fn x => (fn y => x+y); (*stores 5 in 'it'*) myadd2 5; (*passes 6 into the 'it',thereby adding 5 and 6, returning 11*) it 6; (*if you are watching the video along with these notes please be aware this is where the fire alarm goes off*) (*brace yourself*) (*returns f applied to x*) fn f => fn x => f x; (*same as previous however restricted to ints*) val myintapp = fn f => fn x => (f (x:int)):int; (*feeds the square function into int app*) myintapp (fn x => x*x); (*feeds 5 into the square function that was defined previously, returns 25*) it 5; (*the same as myintapp, however the function is applied twice.*) val myintdoubleapp = fn f => fn x => f((f (x:int)):int); (*defines the square function as before, this time with a name*) val mysquare = fn x => x*x; (*feeds mysquare into myintdoubleapp*) myintdoubleapp mysquare; (*feeds 5 into the end of the myintdoubleapp*) it 5; (*polymorphically takes elements of type alpha and beta, returns the element of type alpha*) fn (x,y) => x; (*the same as myintdoubleapp, but without a name*) fn f => fn x => f(f x); (*demonstrating that two strings cannot be concatenated with the '+' operator, this returns a type error*) "hello" + "hello"; (*an example of how to concatenate strings properly with the '^' operator*) "hello"^"hello"; (*a deconstruction of the '^' operator*) op ^; (*takes a string and concatenates it with itself*) val mydoublestring = fn x => x^x; (*applies mydoublestring to mydoubleapp, in a sense making a myquadrupleapp*) mydoubleapp mydoublestring; (*returns 4 'allo's in one string*) it 'allo';