Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in Standard Meta Language of New Jersey (SML) and use only recursive definitions built up from the basic built-in functions! These functions takes a

Solve in Standard Meta Language of New Jersey (SML) and use only recursive definitions built up from the basic built-in functions!

These functions takes a 2-tuple (e.g. (N,L)) where the first element is an integer (N) and the second is a list (L). The idea is to produce a result in which the elements of the original list have been collected into lists each containing n elements (where N is the integer argument). The leftover elements (if there is any) are included as a tuple with less than N elements. Thus the type of each of these is: int * 'a list -> 'a list list.

The difference between the two functions is how they handle the left-over elements of the list when the integer doesn't divide the length of the list evenly. pairNleft treats the initial elements of the list as the extras, thus the result starts with a list of between 1 and N elements and all the remaining elements of the result list contain N elements. pairNright does the opposite: the final group contains between 1 and N elements and all the rest contain N elements. Note: these functions are not required to be tail-recursive. Examples:

> pairNleft (2,[1, 2, 3, 4, 5])

[[1], [2, 3], [4, 5]]

> pairNright (2,[1, 2, 3, 4, 5])

[[1, 2], [3, 4], [5]]

> pairNleft (3,[1, 2, 3, 4, 5])

[[1, 2], [3, 4, 5]]

> pairNright (3,[1, 2, 3, 4, 5])

[[1, 2, 3], [4, 5]]]

> pairNright (3,[]) (*this may give a warning since the type cant be inferred*)

[[]]

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

2. How were various roles filled?

Answered: 1 week ago

Question

2. What process will you put in place to address conflicts?

Answered: 1 week ago