Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write HASKELL definitions for the following functions: 1. order a b c: returns a list of a, b and c such that the first element

Write HASKELL definitions for the following functions:

1. order a b c: returns a list of a, b and c such that the first element is less-or-equal the second, and the second is less-or-equal the third element. For example, order 4 2 3 should return [2,3,4].

2. fltr f lst: returns the list consisting of members of lst that make the function f return True when applied to it. For example, fltr even [1,2,2,5,8,4] should return [2,2,8,4]. f can be any function that takes one parameter of the same type as list elements.

3. compute lst: lst is a list of pairs of numbers, and the answer is a list formed as follows if the first component is smaller than the second one, then their multiplication is in the result. Otherwise, their addition is in the result. 1. Example 1: compute [(2,3),(8,4),(4,6)] should return [6,12,24]. 2. Example 2: compute [(8,7),(1,1),(4,5),(2,5)] should return [15,2,20,10].

4. eliminate lst: returns a list, obtained from lst, such that a is in the result only if it is smaller than the next element that follows it in lst. For example, eliminate [4,3,6,5,7,9,6] should return [3,5,7]. Note that the last element of lst will never be in the result, because there is no other element after it. (hint: use the pattern (x:(y:t)) to access the first and second elements in front of the list. Or you can use head and tail functions.)

5. gpa lst: computes the gpa in a given semester, given a list of (course,credit,grade) tuples. An A counts as 4, B counts as 3, C counts as 2 and D counts as 1. Example: gpa [(cmse318,4, A), (math163,3, C)] should return 3.14 ((4*4+2*3)/7).

6. howmany elem a_list: returns how many elems are in a_list. For example, howmany 'b' ['a', 'b', 'c', 'b', 's'] should return 2.

7. pair_lists list1 list2: returns a list of pairs, where the first component of a pair in position i is in position i of list2 and the second component of a pair in position i is in position i of list1. For example, pair_lists [3,4,5] [10,20,30] should return [(10,3),(20,4),(30,5)]. You can assume that the two lists have the same size.

8. classify_g n: returns a letter grade based upon a numeric grade, according to the following schema: n>=90 'A', 80=90 'A', 80<=n<=89 'B', 70<=n<79 'C', otherwise 'D'. For example, classify_i 87 should return 'B'. . Define classify_g with guards to implement this function.

9. classify_i n: returns a letter grade based upon a numeric grade, according to the following schema: n>=90 'A', 80<=n<=89 'B', 70<=n<79 'C', otherwise 'D'. For example, classify_i 87 should return 'B'. Define classify_i with the if expression to implement this function.

10. first_odds n: returns a list of the first n odd numbers. For example, first_odds 5 should return [1,3,5,7,9].

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

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago