Write a function buckets : ('a 'a -> bool) -> 'a list -> 'a list list...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function buckets : ('a 'a -> bool) -> 'a list -> 'a list list that partitions a list into equivalence classes. That is, buckets equiv 1st should return a list of lists where each sublist in the result contains equivalent elements, where two elements are considered equivalent if equiv returns true. For example: buckets (=) [1;2;3;4] = [[1]; [2]; [3];[4]] buckets (=) [1;2;3; 4;2;3;4;3;4] = [[1]; [2:2]; [3;3;3];[4;4;4]] buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1;2;3;4;5;6] = [[1;4]; [2;5];[3;6]] The order of the buckets must reflect the order in which the elements appear in the original list. For example, the output of buckets (=) [1;2;3;4] should be [[1]; [2]; [3];[4]] and not [[2]; [1]; [3];[4]] or any other permutation. The order of the elements in each bucket must reflect the order in which the elements appear in the original list. For example, the output of buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1; 2; 3; 4; 5; 6] should be [[1;4]; [2;5]; [3;6]] and not [[4;11; [5;2]; [3;6]] or any other permutations. Assume that the comparison function ('a -> 'a -> bool) is commutative, associative and idempotent. You are not allowed to use sets or hash tables in your solution. The list concatenation operator @ may come in handy. Feel free to use helper functions. let buckets p 1 = (* YOUR CODE HERE *) assert (buckets (=) [1;2;3;4] = [[1] [2] [3] [4]]); assert (buckets (=) [1;2;3; 4;2;3; 4;3;4] = [[1]; [2;2]; [3;3;3]; [4; 4;4]]); assert (buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1;2;3; 4; 5;6] = [[1;4]; [2;5]; [3;6]]); Activat Write a function buckets : ('a 'a -> bool) -> 'a list -> 'a list list that partitions a list into equivalence classes. That is, buckets equiv 1st should return a list of lists where each sublist in the result contains equivalent elements, where two elements are considered equivalent if equiv returns true. For example: buckets (=) [1;2;3;4] = [[1]; [2]; [3];[4]] buckets (=) [1;2;3; 4;2;3;4;3;4] = [[1]; [2:2]; [3;3;3];[4;4;4]] buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1;2;3;4;5;6] = [[1;4]; [2;5];[3;6]] The order of the buckets must reflect the order in which the elements appear in the original list. For example, the output of buckets (=) [1;2;3;4] should be [[1]; [2]; [3];[4]] and not [[2]; [1]; [3];[4]] or any other permutation. The order of the elements in each bucket must reflect the order in which the elements appear in the original list. For example, the output of buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1; 2; 3; 4; 5; 6] should be [[1;4]; [2;5]; [3;6]] and not [[4;11; [5;2]; [3;6]] or any other permutations. Assume that the comparison function ('a -> 'a -> bool) is commutative, associative and idempotent. You are not allowed to use sets or hash tables in your solution. The list concatenation operator @ may come in handy. Feel free to use helper functions. let buckets p 1 = (* YOUR CODE HERE *) assert (buckets (=) [1;2;3;4] = [[1] [2] [3] [4]]); assert (buckets (=) [1;2;3; 4;2;3; 4;3;4] = [[1]; [2;2]; [3;3;3]; [4; 4;4]]); assert (buckets (fun x y-> (=) (x mod 3) (y mod 3)) [1;2;3; 4; 5;6] = [[1;4]; [2;5]; [3;6]]); Activat
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Two-dimensional array operations: Movie Ratings program ** You have recently collected reviews from four movie reviewers where the reviewers are numbered 1-4. Each reviewer has rated six movies where...
-
Evaluate each expression if possible. V0.49
-
A 1.5-kg block A rests on a 1.5-kg block B and is attached to a spring of constant 180 N/m. The coefficients of friction between the two blocks are 0.35 s = and 0.30 k = and the coefficients of...
-
The condensed balance sheet as of December 31, 2014, for Van Den Boom Enterprises follows: Revenues and expenses (other than amortization) are predicted to be $65,000 and $20,000, respectively, for...
-
If the IRR of Alternative \(A\) is 18 percent, the IRR of Alternative B is 16 percent, and MARR is 12 percent, which of the following is correct? a. Alternative B is preferred over Alternative A. b....
-
The vice president of operations of I4 Computers Inc. is evaluating the performance of two divisions organized as investment centers. Invested assets and condensed income statement data for the past...
-
At a price of $340, Vurtego sold 1050 pogo sticks per year. After airing on Shark Tank, demand increased, and Vurtego sold 1950 pogo sticks the following year for $460 a unit. Using the mid-point...
-
Condensed financial data for Next Wave Company follow: NEXTWAVE COMPANY Comparative Statement of Financial Position NEXTWAVE COMPANY Statement of Earnings Data For the year ended December 31, 2011...
-
Choose the socializing factor (family, culture, or media), that you believe influences self-concept the most. Explain your answer.
-
2) Family Fun reported credit sales of $800,000, cash collections of $550,000 and bad debt expense of $15,000 for last year. Accounts receivable had a balance of $1,000,000 at the beginning of the...
-
If the future value of an ordinary, 7-year annuity is $9,000 and interest rates are 9.0 percent, what's the future value of the same annuity due? (Round your answer to 2 decimal places.)
-
Burke Tires just paid a dividend of Do=$1.3. Analysts expect the company's dividend to grow by 30% this year, by 10% in Year 2, and at a constant rate of 5% in Year 3 and thereafter. The required...
-
KL and LP are both engaged in retKL limited and LP limited are both engaged in retailing but they seem to take a different approach. one of them prides itself on personal service and the other on...
-
What are the differences between cash and accrual basis accounting? Provide an example of each. Accrual accounting requires adjusting entries. Provide an example of an adjusting entry.
-
Discuss the difference in being driven, as King Saul was, and being called, as John the Baptist was. Incorporate how you can apply this to your life while a student and to your future profession in...
-
Conduct a VRIO analysis by ranking Husson University (in Maine) business school in terms of the following six dimensions relative to the top three rival schools. If you were the dean with a limited...
-
Construct function prototypes that match the following descriptions: a. igor() takes no arguments and has no return value. b. tofu() takes an int argument and returns a float. c. mpg() takes two type...
-
Write a template function maxn() that takes as its arguments an array of items of type T and an integer representing the number of elements in the array and that returns the largest item in the...
-
Write a program that asks the user to enter his or her first name and then last name, and that then constructs, stores, and displays a third string consisting of the users last name followed by a...
-
Consider the system of Fig. P4.4-5. The filter transfer function is \(D(z)\). (a) Express \(C(z)\) as a function of \(E\). (b) A discrete state model of this system does not exist. Why? (c) What...
-
Find the \(z\)-transform of the following functions. The results of Problem 4.5-3 may be useful. (a) \(E(s)=\frac{6 \varepsilon^{-0.3 T s}}{(s+1)(s+2)(s+3)}\) (b) \(E(s)=\frac{4 \varepsilon^{-0.6 T...
-
Consider again the system of Fig. P4.4-5. Add a sampler for \(E(s)\) at the input. Given \[ G_{1}(s)=\frac{1}{s+10} \quad D(z)=\frac{z-0.5}{z-1} \quad G_{2}(s)=\frac{s}{s^{2}+9 s+23} \] find \(c(k...
Study smarter with the SolutionInn App