diff options
author | Camil Staps | 2016-09-24 14:19:08 +0200 |
---|---|---|
committer | Camil Staps | 2016-09-24 14:19:08 +0200 |
commit | 408c53f5dbffa0ab147ddbff1ee2f85a57382474 (patch) | |
tree | c5a97fabe16e838a5e63bf4f30003eb642f39f01 | |
parent | Fix issue with overwritten references (diff) |
Removed strictness paragraph from docs; doesn't apply anymore
-rw-r--r-- | doc/examples.tex | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/doc/examples.tex b/doc/examples.tex index 421217c..7cffda5 100644 --- a/doc/examples.tex +++ b/doc/examples.tex @@ -66,52 +66,3 @@ subtraction. Hence, the example is rewritten as: A complete overview of the \fuspel{code} names can be found in \autoref{sec:code}. - -\subsection{Strictness} -\label{sec:examples:strictness} - -By default, expressions are rewritten using the leftmost outermost rewriting -strategy. This is guaranteed to find a normal form if one exists, but can be -inefficient as it can lead to duplicate calculation. Consider the following -example: - -\begin{lstlisting} - mul x y = code mul x y; - double x = (x, x); - main = double (mul 5 10); -\end{lstlisting} - -The result is \fuspel{(50,50)}. The expression is rewritten to \fuspel{(mul 5 -10, mul 5 10)}, and only then the \fuspel{mul} calls are rewritten. This is -inefficient, because we have to multiply the numbers twice. - -We can force another rewriting strategy by adding a strictness annotation -(\fuspel{!}) to the argument of \fuspel{double}: - -\begin{lstlisting} - mul x y = code mul x y; - double !x = (x, x); - main = double (mul 5 10); -\end{lstlisting} - -The result is the same, but the multiplication is only executed once. To apply -the \fuspel{double} rule, its argument must be fully evaluated due to the -strictness annotation. Therefore, the expression is first rewritten to -\fuspel{double 50}. - -One must be careful with adding strictness annotations. Consider the following -program: - -\begin{lstlisting} - mul x y = code mul x y; - app f (a,b) = (f a, f b); - fst (x,_) = x; - double !x = (x, x); - main = app fst (double (mul 5 10, mul 10 20)); -\end{lstlisting} - -In the call to \fuspel{double}, both \fuspel{mul 5 10} and \fuspel{mul 10 20} -are fully rewritten due to the strictness annotation. However, only the first -elements of the resulting tuples are used: the result is \fuspel{(50,50)}. We -did not need to fully rewrite \fuspel{mul 10 20}, so the strictness annotation -gave us more work. |