(*the add function*) fn (x,y) => x+y; (*the following are examples of how not to layout code, even though this will still compile*) fn (x,y) => x+y ; fn (x,y) => x + y; (*how not to write a NAND function*) fun mynand (x,y) = not (x andalso y); (*showing a slight lack of versatility in input of the previous function as it requires a tuple, this gives an error*) mynand true; (*a way of circumnavigating this lack of versatility, note the lack of a tuple at the input.*) fun mynand x y = not (x andalso y); (*a much better way of writing the nand*) fun mynand false false = true | mynand false true = true | mynand true false = true | mynand true true = false; (*an even better way of writing this function *) fun mynand true true = false | mynand _ _ = true; (*the same but with more sugar, however uses more memory*) fun mynand true true = false | mynand x y = true; (*creates a list of integers from 1 - 5*) [1,2,3,4,5]; (*creates a list of integers from 1 - 5, the hardcore way*) 1::(2::(3::(4::(5::nil)))); (*stores a list of 2-5 as myintlist*) val myintlist = [2,3,4,5]; (*pushes 1 onto my int list*) 1::myintlist; (*deconstructs the *) op ::; (*shows an empty polymorphic list*) []; (*demonstrates that nil is another syntax for an empty alpha list, returns true*) nil = []; (*pushes "Two" onto an empty polymorphic list, thereby giving it a type and therefore making it no longer polymorphic*) "Two"::[]; (*demonstrating that all elements in a list must be of the same type*) [2,"Two"]; (*showing that tuples are more fluid in this regard, this runs fine unlike the previous example*) (2,"Two"); (*pushes a tuple of mixed types onto a list*) (2,"Two")::[(4,"Four")]; (*gives the head of the list *) hd; (*gives the rest of the list*) tl; (*returns (4,"Four"), as this is the contents of the list that isn't the head*) tl [(2,"Two"),(4,"Four")]; (*returns 2, the first element in the list*) hd [2,30]; (*by contrast, here is the same action but with a tuple*) #1 (2,30); (*tries to give the head of an empty list, raises exception*) hd []; (*tries to give tail of an empty list, rasises exception*) tl []; (*gives tail of list with only one element, returns an empty list of type int list*) tl [1]; (*gives the head of a list with only one element, returns one element of type int*) hd [1]; (*pushes empty list onto an empty list*) []::[]; (*pushes a list of integers onto an empty list*) [1]::[]; (*pushes an int list onto a list of integers, raises an error*) [1]::[1]; (*pushes a int ontp a list of integers*) [1]::[[2],[3]]; (*pushes an integer to the right side of the list, my favourite function for obvious reasons. this uses concatenation*) fun camfun l x = l@[x]; (*a much more fun way of making camfun*) fun camfun [] x = [x] | camfun (h::t) x = h::(camfun t x);