Question
F# has a predened list datatype. Strictly speaking, however, it is not necessary, For instance, integer lists could be simulated by the following user dened
F# has a predened list datatype. Strictly speaking, however, it is not necessary, For instance, integer lists could be simulated by the following user dened datatype type ilist = E | L of int * ilist where the constructor E stands for the empty list and the constructor L builds a new list by adding a number in front of another list. Then one can represent, say, a list with elements 1,4,6,7, in that order, with the ilist value L(1, L(4, L(6, L(7, E)))). 1 Using pattern matching and recursion, implement the following functions manipulating ilist values
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))))Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started