Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 3: Define a function less of type int * int list - > int list so that l

ID: 3799311 • Letter: E

Question

Exercise 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.

Explanation / Answer

/** Lets Describing 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 given list L. *) (/* Correct, but non-pattern matching version is : 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, y::ys) = if (e=y) then true else member(e, ys); member (1, []); member (1, [1, 2]); member (1, [2, 1, 3]); member (1, [2, 3]); (/* Describing 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)