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
c) elemIndex :: Eq a => a → [a] → Maybe Int
group :: Eq a => [a] → [[a]]
group "Mississippi" == ["M","i","ss","i","ss","i","pp","i"]
Write a function that determines whether an integer is prime.
Construct an infinite list containing all prime numbers.
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.
8. Sorting
Write a function that sorts a list of values using one of the following algorithms: insertion sort; selection sort; merge sort; quicksort.
Construct an infinite list allPairs
that contains all pairs of positive integers. Every pair must appear
exactly once in the list.
Construct an infinite diagonal matrix as an infinite list of lists:
[[
1
,
0
,
0
,
0
,
...],
[0
,
1
,
0
,
0
,
...],
[0
,
0
,
1
,
0
,
...],
.
.
.
]
Write a function permutations :: [a] ->
[[a]]
that returns a list of all permutations of a given list.
Do not assume that the type a implements Eq.
Write a function triples
that takes
an integer N and returns a list of integer triples (a, b, c) with
0 < a < b < c ≤ N such that
a2 + b2 = c2. If two triples are
multiples of each other (e.g. (3, 4, 5) and (6, 8, 10)),
only the smaller of them (e.g. (3, 4, 5)) should appear in the list.
> triples 15 [(3,4,5),(5,12,13)]