Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago