(******** 7.2 *******) (* Define a function member of type ''a * ''a list -> bool so that member(e, L) is true if and only if e is an element of the list L. *) (* Correct, but non-pattern matching version: fun member (e, L) = if null L then false else if e = hd(L) then true else member (e, tl(L)); *) fun member (e, nil) = false | member (e, x::xs) = if (e=x) then true else member(e, xs); member (1, []); member (1, [1, 2]); member (1, [2, 1, 3]); member (1, [2, 3]); (*********** 7.3 *************) (* Define a function less of type int * int list -> int list so that less (e, L) is a list of all the integers in L that are less than e *) (* Correct, but non-pattern matching version: fun less (e, L) = if null L then nil else if hd(L) < e then hd(L) :: less(e, tl(L)) else less (e, tl(L)); *) fun less (e, nil) = nil | less (e, x::xs) = if x < e then x :: less(e, xs) else less (e, xs); (************ 7.4 *****************) (* Define a function repeats of type ''a list -> bool so that repeats (L) is true if and only if the list L has two equal elements next to each other *) (* Correct, but non-pattern matching version: fun repeats (L) = if null L orelse null(tl(L)) then false else if hd(L) = hd(tl(L)) then true else repeats (tl(L)); *) fun repeats (nil) = false | repeats (x::nil) = false | repeats (x::xs) = if x = hd(xs) then true else repeats(xs);