What are the types of these functions?
triple x = 3 * x
even x = (x `mod` 2 == 0)
palindrome xs = (reverse xs == xs)
f x = f x
Write these functions (which are all built into the standard library):
a) isPrefixOf :: Eq a => [a] → [a] →
Bool
isInfixOf :: Eq a => [a] → [a] → Bool
group :: Eq a => [a] → [[a]]
group "Mississippi" == ["M","i","ss","i","ss","i","pp","i"]
Implelement the built-in function cycle
that takes a list L and returns an infinite list consisting of L
repeated over and over:
> take 10 (cycle "abc") "abcabcabca"
Construct an infinite list containing all Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, ...
Write a function that determines whether an integer is prime.
Construct an infinite list containing all prime numbers.
Write a function that computes the greatest common divisor of two numbers. It should work with any integral type, e.g. either Int or Integer.
Write a function add_vec
that adds
two vectors represented as lists. Give your function the most general
possible type.
Write a function dot
that computes
the dot product of two vectors represented as lists.
Write a function add
that
adds two matrices represented as lists of lists.