Standard ML of New Jersey (32-bit) v110.99 [built: Thu Dec 24 11:01:10 2020] - fun f1 x = 1 + hd x; val f1 = fn : int list -> int - f1 [1,2,3] = ; val it = 2 : int - - - fun f1 x :: xs = 1 + x; stdIn:6.10-6.12 Error: infix operator "::" used without "op" in fun dec stdIn:6.10-6.12 Error: data constructor :: used without argument in pattern - - - fun f1 (x :: xs) = 1 + x; stdIn:8.5-8.25 Warning: match nonexhaustive x :: xs => ... val f1 = fn : int list -> int - - - fun f1 x = 1 + hd x; val f1 = fn : int list -> int - f1 []; uncaught exception Empty raised at: smlnj/init/pervasive.sml:193.19-193.24 - - - fun f1 (x :: xs) = 1 + x; stdIn:14.5-14.25 Warning: match nonexhaustive x :: xs => ... val f1 = fn : int list -> int - f1 []; uncaught exception Match [nonexhaustive match failure] raised at: stdIn:14.25 - - - fun f1 x = if null x then 0 else 1 + hd x; val f1 = fn : int list -> int - f1 [1,2,3]; val it = 2 : int - f1 []; val it = 0 : int - - - - fun f1 [] = 0 = | f1 (x :: xs) = 1 + x; val f1 = fn : int list -> int - f1 []; val it = 0 : int - f1 [1,2,3]; val it = 2 : int - - - fun f1 x = if null x then = 0 = else = 1 + hd x; val f1 = fn : int list -> int - - - fun f2 x = hd x + hd (tl x); val f2 = fn : int list -> int - f2 [1,3]; val it = 4 : int - f2 [1,2,3,4]; val it = 3 : int - f2 [5,2,3,4]; val it = 7 : int - f2 [5]; uncaught exception Empty raised at: smlnj/init/pervasive.sml:193.19-193.24 - - f2 []; uncaught exception Empty raised at: smlnj/init/pervasive.sml:193.19-193.24 - - - fun f2 (x :: y :: ys) = x + y; stdIn:44.5-44.30 Warning: match nonexhaustive x :: y :: ys => ... val f2 = fn : int list -> int - - fun f2 x = if null x then 0 else if null (tl x) then hd x else hd x + hd (tl x); val f2 = fn : int list -> int - - - f2 []; val it = 0 : int - f2 [3]; val it = 3 : int - f2 [3, 4]; val it = 7 : int - - -