Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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) list

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+How might you use it to help find a way to resolve that problem?

Answered: 1 week ago