CS152
Chris Pollett
Apr. 20, 2009
As we talk about the above we'll continue to introduce ML.
2 *3; (* or *) op* (2,3);
fun my_mult (x, y) = x*y;one can make it infix using the command:
infix my_mult;
datatype Color_Type = Red | Green | Blue;
Type Unit_Interval is range 0.0..1.0;
A function which can access the bound variables from the scope in which it is defined is called a:
U × V = {(u, v) | u is in U and v is in V}
type my_int_pair = int * int; val a:my_int_pair = (2, 3);
#1(2, 3); (*returns 2 *) #2(2,3); (*returns 3*)
struct Person {char *name; int age;};
type person = {name: string, age:int}; val my_person:person = {name="bob", age=12}; #name(my_person);
union IntOrReal {int i; double r;} b;
datatype IntOrReal = IsInt of int | IsReal of real; val x = IsReal(2.3); fun my_print x = case x of IsInt(i) => print("integer") | IsReal(r ) => print("real");
Subtype IRInt is IntOrReal(IsInt);