Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You can use the following functions from the SML Basis Library, but not any others. http://sml-family.org/Basis/top-level-chapter.html http://sml-family.org/Basis/list.html http://sml-family.org/Basis/list-pair.html 2. (i) Code in SML a function
You can use the following functions from the SML Basis Library, but not any others.
http://sml-family.org/Basis/top-level-chapter.html http://sml-family.org/Basis/list.html http://sml-family.org/Basis/list-pair.html
2. (i) Code in SML a function replicate 'a * int -> 'a list that returns the list consisting of the given number of copies of the given value. (If the number is 0, the function must return the empty list.) - replicate 17 3; val it [17, 17, 17] : int list (ii) Code a function uncompress ('a * int) list - 'a list that returns the list where each one of the given values is listed in the associated number of copies. (Use replicate.) uncompress [(17, 3), (42, 5), (1011, 2)]; val it-[17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011] : int list (ii) Code a function maxSegsEq 'a list -> ('a list) list that breaks the given list down into maximal segments of equal values maxSegsEq [17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011]; val it = [[17, 17, 17], [42, 42, 42, 42, 42], [1011, 1011]] : (int list) list (iv) Code a function compress: 'a list -> ('a * int) list that returns the length and the replicated value of each of the maximum seqments of equal elements in the given list. (Use maxSegsEq.) compress [17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011]; val it = [(17, 3), (42, 5), (1011, 2) ] : (int * int) list 2. (i) Code in SML a function replicate 'a * int -> 'a list that returns the list consisting of the given number of copies of the given value. (If the number is 0, the function must return the empty list.) - replicate 17 3; val it [17, 17, 17] : int list (ii) Code a function uncompress ('a * int) list - 'a list that returns the list where each one of the given values is listed in the associated number of copies. (Use replicate.) uncompress [(17, 3), (42, 5), (1011, 2)]; val it-[17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011] : int list (ii) Code a function maxSegsEq 'a list -> ('a list) list that breaks the given list down into maximal segments of equal values maxSegsEq [17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011]; val it = [[17, 17, 17], [42, 42, 42, 42, 42], [1011, 1011]] : (int list) list (iv) Code a function compress: 'a list -> ('a * int) list that returns the length and the replicated value of each of the maximum seqments of equal elements in the given list. (Use maxSegsEq.) compress [17, 17, 17, 42, 42, 42, 42, 42, 1011, 1011]; val it = [(17, 3), (42, 5), (1011, 2) ] : (int * int) listStep 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