on master help sign in
Tutorial updates
commitd466a82e634cde529c91f934568003fb880cf892 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateSun 26 Feb 2012, 17:26 (15 years ago) parent3f13043
6 files changed+44−7
tutorial/examples/interp.idr+3 tutorial/idris-tutorial.pdf tutorial/interp.tex+36−2 tutorial/intro.tex+1−1 tutorial/starting.tex+3−3 tutorial/theorems.tex+1−1
tutorial/examples/interp.idr+3
@@ -58,6 +58,9 @@ using (G : Vect Ty n)
5858testFac : Int
5959testFac = interp [] fact 4
6060
61+unitTestFac : so (interp [] fact 4 == 25)
62+unitTestFac = oh
63+
6164main : IO ()
6265main = do putStr "Enter a number: "
6366 x <- getLine
tutorial/idris-tutorial.pdf

Binary file not shown.

tutorial/interp.tex+36−2
@@ -341,12 +341,12 @@ at the \Idris{} interactive environment is shown in Figure \ref{factrun}.
341341$ idris interp.idr
342342 ____ __ _
343343 / _/___/ /____(_)____
344− / // __ / ___/ / ___/ Version 0.9.1
344+ / // __ / ___/ / ___/ Version 0.9.2
345345 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
346346 /___/\__,_/_/ /_/____/ Type :? for help
347347
348348Type checking ./interp.idr
349−*interp> :exec interp
349+*interp> :exec
350350Enter a number: 6
351351720
352352*interp>
@@ -374,4 +374,38 @@ parameters at the point where the cast is applied.
374374There are casts defined between all of the primitive types, as far as
375375they make sense.
376376
377+\subsection{Unit testing}
378+
379+Recall the \texttt{so} data type:
380+
381+\useverb{sotype}
382+
383+\noindent
384+This requires its parameter to be a \texttt{True} value. One simple application of this
385+is to perform unit testing of functions at compile time. For example, we know that
386+\texttt{4! = 24} so we can set up a test case as follows:
387+
388+\begin{SaveVerbatim}{unitTestFac}
389+
390+unitTestFac : so (interp [] fact 4 == 24)
391+unitTestFac = oh
392+
393+\end{SaveVerbatim}
394+\useverb{unitTestFac}
395+
396+\noindent
397+For the program the compile, the test case must pass. If we change \texttt{24} to \texttt{25},
398+say, we will get an error message like the following:
399+
400+\begin{SaveVerbatim}{unitTestErr}
401+
402+Type checking ./interp.idr
403+interp.idr:64:Can't unify so True with so False
404+
405+Specifically:
406+ Can't unify True with False
407+
408+\end{SaveVerbatim}
409+\useverb{unitTestErr}
410+
377411
tutorial/intro.tex+1−1
@@ -62,7 +62,7 @@ verifying systems software.
6262\subsection{Example Code}
6363
6464This tutorial includes some example code, which has been tested with \Idris{} version
65−0.9.1. The files are available in the \Idris{} distribution,
65+0.9.2. The files are available in the \Idris{} distribution,
6666so that you can try them out easily,
6767under \texttt{tutorial/examples}. However, it is strongly recommended that you
6868type them in yourself, rather than simply loading and reading them.
tutorial/starting.tex+3−3
@@ -82,7 +82,7 @@ environment. You should see something like the following:
8282$ idris
8383 ____ __ _
8484 / _/___/ /____(_)____
85− / // __ / ___/ / ___/ Version 0.9.1
85+ / // __ / ___/ / ___/ Version 0.9.2
8686 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
8787 /___/\__,_/_/ /_/____/ Type :? for help
8888
@@ -102,7 +102,7 @@ as shown in Figure \ref{cmds}. Figure \ref{run1} shows an example run in which
102102the program is compiled to the executable \texttt{hello}.
103103
104104\begin{SaveVerbatim}{cmds}
105−Idris version 0.9.1
105+Idris version 0.9.2
106106-------------------
107107
108108 Command Arguments Purpose
@@ -128,7 +128,7 @@ Idris version 0.9.1
128128$ idris hello.idr
129129 ____ __ _
130130 / _/___/ /____(_)____
131− / // __ / ___/ / ___/ Version 0.9.1
131+ / // __ / ___/ / ___/ Version 0.9.2
132132 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
133133 /___/\__,_/_/ /_/____/ Type :? for help
134134
tutorial/theorems.tex+1−1
@@ -410,7 +410,7 @@ The totality check is currently very conservative. To be recorded as total, a fu
410410\item Be \emph{well-founded} --- i.e. each recursive call must have a decreasing argument
411411\item Not call any non-total functions
412412\item Not use any data types which are not \emph{strictly positive}
413−\item (In version 0.9.1) Not be mutually recursive
413+\item (In version 0.9.2) Not be mutually recursive
414414\end{itemize}
415415
416416\noindent