Question: Needs to be in ML. If possible, use anonymous functions for question 5 and 6. module type INTSET - sig type t val empty :

Needs to be in ML. If possible, use anonymous functions for question 5 and 6.

Needs to be in ML. If possible, use anonymous functions for question

5 and 6. module type INTSET - sig type t val empty

module type INTSET - sig type t val empty : t val contains : int -> t -> bool val insert : int -> t ->t val remove : int -> t ->t val fold : C'a -> int -> 'a) -> 'a -> t -> 'a : ('a > > 'a -> -> a val to_string: t => string end 5. Complete the module implementation IntSet1 by replacing the calls to failwith with real implemen- tations. Do not modify the provided implementations of insert or contains. In your implementation of fold, follow the order of elements in the list. Hint: Note that insert can cause duplicates to be in the list. Carefully consider how each function will handle duplicates, and try not to do any work you don't have to do. Sample solution is about 30 lines. 6. Write a module implementation IntSet2 that also uses an int list as its internal representation, but keeps this list sorted and duplicate-free. Be careful that all your functions that return new sets maintain this invariant. Also, take advantage of these invariants whenever possible in your functions 1 to gain efficiency or concision. This means that you should not scan through the entire list each time you insert or remove an element. This also means that your solution should not use List.sort, List.sort_uniq, or similar functions (i.e., don't rewrite these or reimplement their functionality in your code). module type INTSET - sig type t val empty : t val contains : int -> t -> bool val insert : int -> t ->t val remove : int -> t ->t val fold : C'a -> int -> 'a) -> 'a -> t -> 'a : ('a > > 'a -> -> a val to_string: t => string end 5. Complete the module implementation IntSet1 by replacing the calls to failwith with real implemen- tations. Do not modify the provided implementations of insert or contains. In your implementation of fold, follow the order of elements in the list. Hint: Note that insert can cause duplicates to be in the list. Carefully consider how each function will handle duplicates, and try not to do any work you don't have to do. Sample solution is about 30 lines. 6. Write a module implementation IntSet2 that also uses an int list as its internal representation, but keeps this list sorted and duplicate-free. Be careful that all your functions that return new sets maintain this invariant. Also, take advantage of these invariants whenever possible in your functions 1 to gain efficiency or concision. This means that you should not scan through the entire list each time you insert or remove an element. This also means that your solution should not use List.sort, List.sort_uniq, or similar functions (i.e., don't rewrite these or reimplement their functionality in your code)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!