• Home
  • Textbooks
  • Programming in Haskell
  • First steps

Programming in Haskell

Graham Hutton

Chapter 2

First steps - all with Video Answers

Educators


Chapter Questions

Problem 1

Work through the examples from this chapter using GHCi.

Check back soon!
00:32

Problem 2

Parenthesise the following numeric expressions:
$$
\begin{aligned}
& 2^{\wedge} 3^{\star} 4 \\
& 2 * 3+4 * 5 \\
& 2+3 * 4 \wedge 5
\end{aligned}
$$

K B
K B
Numerade Educator
02:59

Problem 3

The script below contains three syntactic errors. Correct these errors and then check that your script works properly using $\mathrm{GHCi}$.
$$
\begin{aligned}
& \mathrm{N}=\mathrm{a} ' \mathrm{div} \text { length } \mathrm{xs} \\
& \text { where } \\
& \mathrm{a}=10 \\
& \mathrm{xs}=[1,2,3,4,5]
\end{aligned}
$$
where
$a=10$
$x s=[1,2,3,4,5]$

Ernest Castorena
Ernest Castorena
Numerade Educator
02:42

Problem 4

The library function last selects the last element of a non-empty list; for example, last $[1,2,3,4,5]=5$. Show how the function last could be defined in terms of the other library functions introduced in this chapter. Can you think of another possible definition?

Bryan Lynn
Bryan Lynn
Numerade Educator
00:14

Problem 5

The library function init removes the last element from a non-empty list; for example, init $[1,2,3,4,5]$ $=[1,2,3,4]$. Show how init could similarly be defined in two different ways.

Amy Jiang
Amy Jiang
Numerade Educator