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 *