Chapter 3 Haskell Test
Unless you are completely confident of your signature-writing skills,
please use “concrete” type classes like Double
or Integer
instead
of class constraints like (Floating a)
or (Integral a)
everywhere
you write code that will actually run.
Part I: No Computer
This is the only part of the test where you should attempt to use class constraints (if you know them).
-
The
whatSig
function takes in an ordered pair, a distance, and two strings. If the ordered pair is within the distance of (0,0), then the answer is the first string, otherwise the answer is the second string. What is an appropriate the signature (only) for this function?whatSig (3,4) 10 "Close" "Far" == "Close"
-
Give an example of an ability that the
Fractional
class constraint provides that is not available with anIntegral
class constraint. -
Give an example of an ability that the
Floating
class constraint provides that is not available withFractional
. -
(
someSqrt
) Write a signature and the function. ThesomeSqrt
function that takes in a list of x values and puts out a list of points:* x values less than 10 are ignored (no corresponding point is output) * otherwise output a point on the graph of $y=\sqrt{x}$
Part II: Computer
-
(
midAvg
) Given a list ofDouble
numbers with 3 or more elements, themidAvg
function gets rid of the first and the last element, then finds the average of the remaining list. Write the complete function, including signature. -
oddVowels. A word is an odd vowel word if all of the vowels in the word appear in odd index positions (remember indexing starts at zero).
- 6o.
odO theWord
: Return all of the odd vowels in the word. - 6a.
odA theWord
: Determine if a single word is an odd vowel word. - 6b.
odB theList
: Return a list of all of the odd vowel words in theList.
odA "xz" == True odA "a" == False odA "raw fud gg" == True odA "pizzza" == True odA "cucumber" == False
- 6o.