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

Write a function in ML (e) union This function returns the union of two sets. Fo

ID: 3877412 • Letter: W

Question

Write a function in ML

(e) union

This function returns the union of two sets. For example, union((3,[2,7,4]), (2,[7,3])) may return (4,[4,2,3,7]) because {2, 7, 4} {7, 3} = {4, 2, 3, 7}.

sample execution

val union = fn : (int * int list) * (int * int list) -> int * int lis

- val S' = (3,[4,2,7]);

val S' = (3,[4,2,7]) : int * int list

- val U = (2,[7,3]);

val U = (2,[7,3]) : int * int list

union(S,U);

val it = (4,[4,2,7,3]) : int * int list

Explanation / Answer

- fun union([],y) = y = | union(a::x,y) = = if member(a,y) then union(x,y) = else a::union(x,y); val union = fn : ''a list * ''a list -> ''a list - union((3[2,7,4]),(2[7,3])); val it = (4[4,2,7,3]) : int list

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote