Question: Use OCaml programming language to generate functions for the following scenarios built-in functions or special forms however, you may implement additional helper functions on top

Use OCaml programming language to generate functions for the following scenarios

Use OCaml programming language to generate functions for the following scenarios built-in

built-in functions or special forms however, you may implement additional helper functions on top of the required ones. Note that some exercises specify whether your solution should be tail-recursive (or not). If unspecified, you may do either. 1. iexpt : Performs integer exponentiation (assuming positive, integer arguments). Given arguments n and e, computes n. E.g., \# iexpt 210; - : int =1024 \# iexpt 53;; - . int =125 2. poly_eval : Given coeffs and x, where coeffs is a list of integer coefficients (a,b,c,) and x is an integer, computes the value of the polynomial ax0+bx1+cx2+ E.g.r \# poly_eval [2;3;4]2;; - : int =24 \# poly_eval [] 10; - : int =0 \# poly_eval [8;4;2;1]4; - : int =120 Your implementation should be tail-recursive. You may use iexpt from the previous exercise. 3. concatenate : Given a list of lists, concatenates all the elements of the argument lists into a single list. E.g., \# concatenate [[1;2;3];[4];[5;6]];; Your implementation should be tail-recursive. Additionally, when building your result list, you should only use cons (::), and your implementation should have linear runtime w.r.t. the total number of elements. Hint it might be helpful to use List.rev at some point in your implementation! 4. merge : Takes two argument lists, both of which contain only integers and are in ascending order. Returns a single list containing all the integers, sorted in ascending order. E.g., \# merge [1;4;8;10][2;3;7;13];; : int list =[1;2;3;4;7;8;10;13] Your implementation should not be tail-recursive (we'll do that next). 5. merge_tail : re-implement the previous function, but this time your implementation should be tail-recursive. As with your implementation of concatenate, you may only use the :: constructor to build your result list, and it should have linear runtime w.r.t. the total number of integers. 6. run_length_encode : returns a run-length encoding of the argument list. Run-length encoding stores each value together with the number of times it appears (contiguously) in this way, a value that is repeated multiple times can be more efficiently represented. E.g., \# run_length_encode ['a'; 'a'; 'a'; 'a'; 'a'; 'b'; 'b'; 'b'];; : (char * int) list =[(a,5);(b,3)] \# run_length_encode [1;1;6;6;6;6;2];; - : (int * int) list =[(1,2);(6,4);(2,1)] \# run_length_encode [];; Your implementation should be tail recursive. You may assume that adjacent elements can be compared for equality using = 7. run_length_decode : given a run-length encoded list argument, returns the original list. E.g. \# run_length_decode [(a,5); (b,3)];; char list =[a;;a; ' a '; 'a'; 'b'; 'b'; 'b'] 8. split : splits a list of pairs into a pair of lists; the first returned list contains the first components of all of the input pairs, and the second list contains all of the second components, e.g. \# split [(1,2);(3,4);(5,6)];; # split [(C,1) int (lb,2)];3;5],[2;4;6]) - : char list * int list =([a '; ' 'b' ],[1;2])

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!