chs@pv106200% ml ~/wrk/cs/teaching/ics141/ml Moscow ML version 2.00 (June 2000) Enter `quit();' to quit. - datatype color = Red | Green | Blue; > New type names: =color datatype color = (color,{con Blue : color, con Green : color, con Red : color}) con Blue = Blue : color con Green = Green : color con Red = Red : color - Blue; > val it = Blue : color - val twoColors = (Red, Green); > val twoColors = (Red, Green) : color * color - use "degrees.ml"; [opening file "degrees.ml"] > New type names: =degree datatype degree = (degree, {con BS : string -> degree, con MS : string * string -> degree, con PhD : string * string * string -> degree}) con BS = fn : string -> degree con MS = fn : string * string -> degree con PhD = fn : string * string * string -> degree > val strdeg = fn : degree -> string [closing file "degrees.ml"] > val it = () : unit - BS "CompScience"; > val it = BS "CompScience" : degree - print "lkjlkjkl"; lkjlkjkl> val it = () : unit - print (strdeg PhD("CS", "UCI", "Michael Franz")); ! Toplevel input: ! print (strdeg PhD("CS", "UCI", "Michael Franz")); ! ^^^ ! Type clash: expression of type ! string * string * string -> degree ! cannot have type ! degree - print (strdeg (PhD("CS", "UCI", "Michael Franz"))); PhD in CS from UCI under Michael Franz> val it = () : unit - datatype ourList = EmptyList | Cons of int * ourList; > New type names: =ourList datatype ourList = (ourList,{con Cons : int * ourList -> ourList, con EmptyList : ourList}) con Cons = fn : int * ourList -> ourList con EmptyList = EmptyList : ourList - val l = Cons (1, Cons(2, EmptyList)); > val l = Cons(1, Cons(2, EmptyList)) : ourList - fun ourSum EmptyList = 0 | ourSum Cons (i, l) = i + ourSum l; ! Toplevel input: ! ....ourSum EmptyList = 0 ! | ourSum Cons (i, l) = i + ourSum l. ! Mismatch in the number of curried arguments - fun ourSum EmptyList = 0 | ourSum (Cons (i, l)) = i + ourSum l; > val ourSum = fn : ourList -> int - l; > val it = Cons(1, Cons(2, EmptyList)) : ourList - ourSum l ; > val it = 3 : int - fun ourCount EmptyList = 0 | ourCount (Cons (_, l)) = 1 + ourCount l; > val ourCount = fn : ourList -> int - ourCount l; > val it = 2 : int - fun ourCount EmptyList = 0 | ourCount (Cons (_, _)) = 1; > val ourCount = fn : ourList -> int - fun ourCount EmptyList = 0 | ourCount (Cons (_, _)) = 1 + _; ! Toplevel input: ! | ourCount (Cons (_, _)) = 1 + _; ! ^ ! Syntax error. -