Starter Code Programming Language O Caml Q1a Todo Write Tests Pairlists Function Test List Q43907545
starter code
programming language is O’CAML
(* Q1a TODO: Write your own tests for the pairlistsfunction.
You should NOT test lists of different lengths.
*)
let pairlists_tests = [((1;2;3);(4;5;6))
(* Your test cases go here. *)
]
(* Q1a TODO: Implement pairlists. *)
let rec pairlists twolists =
In this question you will write a program that takes two lists of the same length and returns a single list with the items paired together. This will be used in later questions in this assignment; we will need it with floating point items but your code should be polymorphic. The snippet below shows the function name, the type returned by the OCaml system. Your code must have this type. which you must use, and # let rec pairlists twolists = val pairlists : ‘a list * ‘b list -> (‘a * ‘b) list = <fun> We will forbid the use of the List.combine library function that does the same thing. Test inputs are two int lists of the same length and we will check that you have handled the case of empty input lists. Here is an example showing the right way and the wrong way to use pairlists. [1; 2; 3];; # let 11 val 11 : int list # let 12 = [‘a’; ‘b’; ‘c’];; val 12 : char list = [‘a’; ‘b’; ‘c’] # let p1 = pairlists (11, 12);; val p1 : (int * char) list = [(1, ‘a’); (2, ‘b’); (3, ‘c’)] # let el = pairlists 11 12;; Characters 9-18: let el = pairlists 11 12;; %3D [1; 2; 3] %3D %3D AAAAA^^^^ Error: This function has type ‘a list * ‘b list -> (‘a * ‘b) list It is applied to too many arguments; maybe you forgot a ‘;’ Show transcribed image text In this question you will write a program that takes two lists of the same length and returns a single list with the items paired together. This will be used in later questions in this assignment; we will need it with floating point items but your code should be polymorphic. The snippet below shows the function name, the type returned by the OCaml system. Your code must have this type. which you must use, and # let rec pairlists twolists = val pairlists : ‘a list * ‘b list -> (‘a * ‘b) list = We will forbid the use of the List.combine library function that does the same thing. Test inputs are two int lists of the same length and we will check that you have handled the case of empty input lists. Here is an example showing the right way and the wrong way to use pairlists. [1; 2; 3];; # let 11 val 11 : int list # let 12 = [‘a’; ‘b’; ‘c’];; val 12 : char list = [‘a’; ‘b’; ‘c’] # let p1 = pairlists (11, 12);; val p1 : (int * char) list = [(1, ‘a’); (2, ‘b’); (3, ‘c’)] # let el = pairlists 11 12;; Characters 9-18: let el = pairlists 11 12;; %3D [1; 2; 3] %3D %3D AAAAA^^^^ Error: This function has type ‘a list * ‘b list -> (‘a * ‘b) list It is applied to too many arguments; maybe you forgot a ‘;’
Expert Answer
Answer to starter code programming language is O’CAML (* Q1a TODO: Write your own tests for the pairlists function. You should NOT…
OR