| Safe Haskell | Safe |
|---|
S01
Description
Solutions to Exercises for October 12, 2018
Exercise 3
The previous version was
x = mod length data Y
where
{ data = [1..10] Y = 5 }containing the following errors:
datais a keyword and is therefore not allowed as variable name.- In the last line we are using braces (
{and}) to disregard the layout rule. But then items need to be separated by semicolons (;). Yis not allowed as variable name (since it is uppercase).- Missing parentheses around
length data, since it is supposed to be the first argument ofmod.
Exercise 4
nth :: [a] -> Int -> a Source #
nth corresponds to the Prelude function !!, that is, we have
nth xs i = xs !! i
whenever i is between 0 and the length of xs.
Exercise 5
fromTo :: [a] -> Int -> Int -> [a] Source #
Just to get some intuition: for integer lists of the shape [0..k],
fromTo satisfies the property
fromTo [0..k] i j = [i..j]
for all 0 <= i <= j <= k.