ss@arovane % sml Standard ML of New Jersey v110.52 [built: Fri Jan 21 16:42:10 2005] - (* 2.4.1 *) - #2(3,4,5); (* 4 *) val it = 4 : int - hd([3,4,5]); (* 3 *) val it = 3 : int - tl([3,4,5]); (* [4,5]; "(cdr '(3 4 5))" in lisp/scheme *) val it = [4,5] : int list - explode("foo"); implode([#"f", #"o", #"o"]); val it = [#"f",#"o",#"o"] : char list val it = "foo" : string - "c"::["a","t"]; (* ["c", "a", "t"] *) val it = ["c","a","t"] : string list - ["c","o"]@["b","o","l"]; val it = ["c","o","b","o","l"] : string list - concat(["c","a","t"]); (* "cat"; concat(string list); implode([#"c",#"a",#"t"]); implode(char list) *) val it = "cat" : string - (* 2.4.2 *) - #4(3,4,5); (* index no. > tuple length *) stdIn:10.1-10.10 Error: operator and operand don't agree [record labels] operator domain: {4:'Y; 'Z} operand: int * int * int in expression: (fn {4=4,...} => 4) (3,4,5) - hd([]); (* hd(list) where list != nil *) stdIn:1.1-1.7 Warning: type vars not generalized because of value restriction are instantiated to dummy types (X1,X2,...) uncaught exception Empty raised at: smlnj/init/pervasive.sml:191.19-191.24 - #1(1); (* 1 is not a tuple *) stdIn:1.1-1.6 Error: operator and operand don't agree [literal] operator domain: {1:'Y; 'Z} operand: int in expression: (fn {1=1,...} => 1) 1 - explode(["bar"]); (* explode(string) *) stdIn:1.1-2.5 Error: operator and operand don't agree [tycon mismatch] operator domain: string operand: string list in expression: explode ("bar" :: nil) - implode(#"a",#"b"); (* implode(char list) *) stdIn:1.1-2.7 Error: operator and operand don't agree [tycon mismatch] operator domain: char list operand: char * char in expression: implode (#"a",#"b") - ["r"]::["a","t"]; (* x::(x list) *) stdIn:1.1-2.5 Error: operator and operand don't agree [tycon mismatch] operator domain: string list * string list list operand: string list * string list in expression: ("r" :: nil) :: "a" :: "t" :: nil - tl([]); (* tl(L) where L is a list, not nil *) stdIn:1.1-1.7 Warning: type vars not generalized because of value restriction are instantiated to dummy types (X1,X2,...) uncaught exception Empty raised at: smlnj/init/pervasive.sml:193.19-193.24 - 1@2; (* list@list *) stdIn:1.1-1.4 Error: operator and operand don't agree [literal] operator domain: 'Z list * 'Z list operand: int * int in expression: 1 @ 2 - concat([#"a",#"b"]); (* concat(string list) *) stdIn:1.1-2.8 Error: operator and operand don't agree [tycon mismatch] operator domain: string list operand: char list in expression: concat (#"a" :: #"b" :: nil) - (* 2.4.3 *) - (1.5, ("3", [4,5])); (* real*(string*(int list)) *) val it = (1.5,("3",[4,5])) : real * (string * int list) - [[1,2],nil,[3]]; (* int list list *) val it = [[1,2],[],[3]] : int list list - [(2,3.5),(4,5.5),(6,7.5)]; (* (int*real) list *) val it = [(2,3.5),(4,5.5),(6,7.5)] : (int * real) list - ([#"a",#"b"],[nil,[1,2,3]]); (* (char list) * (int list list) *) val it = ([#"a",#"b"],[[],[1,2,3]]) : char list * int list list - (* 2.4.4 *) - (* (1,2): int*int, (1,2,3): int*int*int *) - (* [1,2]: int list, [1,2,3]: int list *) - (1,2); (1,2,3); val it = (1,2) : int * int val it = (1,2,3) : int * int * int - [1,2]; [1,2,3]; val it = [1,2] : int list val it = [1,2,3] : int list - (* 2.4.5 *) - [[[1]]]; val it = [[[1]]] : int list list list - [(2,#"x")]; val it = [(2,#"x")] : (int * char) list - (["abc"],(4,(8.2,"def")),7); val it = (["abc"],(4,(8.2,"def")),7) : string list * (int * (real * string)) * int - ((11,12),([true,false,3<4,5>6],7.9),(10.2,"xyz")); val it = ((11,12),([true,false,true,false],7.9),(10.2,"xyz")) : (int * int) * (bool list * real) * (real * string) - (((3<4),5),#"X"); val it = ((true,5),#"X") : (bool * int) * char - (* 2.4.6: a string of length 1 -> the character of that string *) - fun str1tochar(s:string) = hd(explode(s)); val str1tochar = fn : string -> char - str1tochar("a"); val it = #"a" : char - str1tochar("X"); val it = #"X" : char -