(* function to compute list length *) fun prob1 nil = 0 | prob1 (h::t) = 1 + prob1(t); (* function to return next to last item in list or nil if length = 1 or 0 *) fun prob2 nil = [] | prob2 [x] = [] | prob2 [x,y] = [x] | prob2 (h::t) = prob2(t); (* function to compute number of even integers *) fun prob3 nil = 0 | prob3(h::t) = if h mod 2 = 0 then 1 + prob3(t) else 0 + prob3(t); (* function to add min and max integers in a list *) fun min nil = 0 | min [x] = x | min (h::t) = Int.min(h, min(t)); fun max nil = 0 | max [x] = x | max (h::t) = Int.max(h, max(t)); fun prob4 [] = 0 | prob4(x) = min(x) + max(x); (* function to create a list of doublets from original list *) fun prob5 nil = [] | prob5 [x] = [x,x] | prob5(h::t) = [h,h]@prob5(t); (* function to remove I'th item from list *) (* fun prob6 (h::t,i : int) = if i=1 then t else [h,prob6(t,i-1)]; *) fun loop(i) = i-1; fun listloop(h::t, i : int) = if i=1 then h::t else t; fun prob6(h::t,i : int) = if loop(i)=1 then listloop(t,0) else prob6(listloop(h::t,1),loop(i));