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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.