Question
Write in Ocaml You should use todo functions This question involves two simple exercises in list manipulation. In the first one you are given a
Write in Ocaml
You should use todo functions
-
This question involves two simple exercises in list manipulation. In the first one you are given a pair: the first member of the pair is an item and the second member is a list of items of the same type as the first member. The output is a boolean that says whether the item is in the list or not. The second function takes a pair of an item and a list and returns a list with the item removed. If the item is not in the list then the same list is returned. Here are the declarations and types.
# let rec memberof pair = ... val memberof : 'a * 'a list -> bool =
# let rec remove (item, lst) = ... val remove : 'a * 'a list -> 'a list = # remove (3, [1; 6; 3; 2; 6; 1; 7; 2; 3; 5]);; - : int list = [1; 6; 2; 6; 1; 7; 2; 5] The lists may contain duplicates; all copies should be removed. Make sure that you deal with empty lists. Even though your functions are polymorphic the grader cannot handle variant types in the mutation tester. So your test examples should all involve integers only. Here is an important style remark: never write if foo then true else false; this should just be foo.
(* Q2 TODO: Write your own tests for the memberof function. *) let memberof_tests = [ (* Your test cases go here. *) ]
(* Q2 TODO: Implement memberof. *) let rec memberof pair = raise NotImplemented ;;
(* (* Q2 TODO: Write your own tests for the remove function. *) let remove_tests = [ (* Your test cases go here. *) ]
(* Q2 TODO: Implement remove. *) let rec remove (item, lst) = raiseNotImplemented ;;
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