4. Write an F# function remove: int-> ilist-> ilist which, given an integer x an
ID: 3743379 • Letter: 4
Question
4. Write an F# function remove: int-> ilist-> ilist which, given an integer x and a list l, "removes" all the occurrences of x from l, that is, returns a list containing (in the same order) all and only the elements of l that differ from x. For example, remove 2 (L(1, L(2, L(3, L(3, L(2, E)))))) sL(1, L(3, L(3, E))); remove 5 (L(1, L(2, L(3, )))) is (L(1, L(2, L(3, E)))). 5. Write an F# function move: ilist-> ilist-> ilist which takes two lists and returns the result of inserting the values of the first list into the second, in reverse order. For example, move (L(1, L(2, L(3, E)))) (L(7,E)) is L(3, L(2, L(1, L(7,E))))Explanation / Answer
//Answer of Question 4.
let remove l ilist : list =
let newList = ilist |> List.map(fun x = match x.head with | l ->x.tail |_->x)
*map function applyes function on each value, and function removes value l if present else element remain untouched *
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.