Starting from:

$29

Homework 2: Vectors

Homework 2: Vectors
Due No Due Date Points None
This homework is ungraded. Feel free to ask and answer questions via Canvas, but don't post
complete solutions.
Consider the type Vect from the slides. For each definition think carefully about the type of the function.
(a) Define a function zipW on vectors that works in the same way as zipWith on lists.
(b) Define a function lst that computes the last element of a vector.
(c) Define a function initial that removes the last element of a vector.
(d) Define a function palin that tests whether a vector is a palindrome.
palin : Eq a => Vect n a -> Bool
Note: You should use the functions lst and initial in your definition. Don't try to define and use a
function for reversing a vector. Here are some test cases.
p1 : Vect 2 Char
p1 = ['a','b']
p2 : Vect 3 Char
p2 = ['a','b','a']
p3 : Vect 4 Char
p3 = ['a','b','b','a']
p4 : Vect 21 Char
p4 = ['a','m','a','n','a','p','l','a','n','a','c','a','n','a','l','p','a','n','a','m','a']
*HW2-Vectors> palin p1
False : Bool
*HW2-Vectors> palin p2
True : Bool
*HW2-Vectors> palin p3
True : Bool
*HW2-Vectors> palin p4
True : Bool

More products