haskell-lectures/VL2/content/VL2_let_vs_where.tex

17 lines
814 B
TeX

These look almost the same, but they are different constructs. \hinline{where} is bound to the pattern matching \hinline{f x =} and may also have access to parts of a function that are not syntactically expressions, e.g.:
\begin{haskellcode}
f x
| cond1 x = a
| cond2 x = g a
| otherwise = f (h x a)
where
a = w x
\end{haskellcode}
While that is not possible with \hinline{let}, which is an actual expression and can be used whenever expressions are allowed (e.g. inside \emph{Monads}, we'll know more about these in a few weeks).
\vspace{\baselineskip}
\\
There are a few more intricacies, but most of the time this is just style consideration:\\ \url{https://wiki.haskell.org/Let_vs._Where}
\pause
\vspace{\baselineskip}
\\
How would we have to rewrite the function in order to use \hinline{let}?