Rather than making a parameterised type into instances of the Functor, Applicative and Monad classes in this order, in practice it is sometimes simpler to define the functor and applicative instances in terms of the monad instance, relying on the fact that the order in which declarations are made is not important in Haskell. Complete the missing parts in the following declarations for the ST type using the do notation.
instance Functor ST where
- fmap :: (a $\rightarrow$ b) $\rightarrow$ ST a $\rightarrow$ ST b
fmap $g$ st $=$ do $\ldots$
instance Applicative ST where
- pure :: a $\rightarrow$ ST a
pure $x=s(\backslash s \rightarrow(x, s))$
$-(\langle *\rangle):$ ST $(\mathrm{a} \rightarrow$ b) $\rightarrow$ ST a $\rightarrow$ ST b
stf $\langle *\rangle \operatorname{stx}=$ do ...
instance Monad ST where
$-(\gg=)::$ ST a $\rightarrow$ (a $\rightarrow$ ST b) $\rightarrow$ ST b
$s t>=f=S(\backslash s \rightarrow$
let $\left(x, s^{\prime}\right)=\operatorname{app}$ st $s$ in app (f $x$ ) $s^{\prime}$ )
Solutions to exercises 1-4 are given in appendix A.