Solve the following problems in Haskell.
What are the types of these functions?
triple x = 3 * x
even x = (x `mod` 2 == 0)
palindrome xs = (reverse xs == xs)
zip [] [] = []
zip (x : xs) (y : ys) = (x, y) :
(zip xs ys)
f x = f x
Which of these functions is equivalent to the built-in operator
||
?
or _ True = True
or True _ = True
or _ _ =
False
or True False = True
or True True = True
or
False True = True
or False False = False
or a b = b || a
Write a function that takes an integer N and returns a list of all integer triples (a, b, c) with 0 < a < b < c ≤ N such that a2 + b2 = c2:
> triples 15 [(3,4,5),(6,8,10),(5,12,13),(9,12,15)]
Your function should run in time O(N3).
Make your function more efficient so that it runs in O(N2 log N). Do not use any floating-point numbers.
Write a function that sorts a list using an insertion sort.
Write a function that sorts a list using a merge sort.
Construct a list ints
of integers from 1 to ∞,
without using the built-in range operator (i.e. [1 ..
]
).
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 allPairs
that contains all
pairs of positive integers. Every pair must appear exactly once in
the list.