on master help sign in
Brief documentation on 'parameters' blocks in tutorial
commitadbe6134670b81e240bf1e7da6d55d6a18f55f60 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateMon 22 Oct 2012, 02:18 (14 years ago) parent919600b
6 files changed+82−6
tutorial/interp.tex+1−1 tutorial/intro.tex+1−1 tutorial/modules.tex+56 tutorial/starting.tex+3−3 tutorial/theorems.tex+1−1 tutorial/typesfuns.tex+20
tutorial/interp.tex+1−1
@@ -344,7 +344,7 @@ at the \Idris{} interactive environment is shown in Figure \ref{factrun}.
344344$ idris interp.idr
345345 ____ __ _
346346 / _/___/ /____(_)____
347− / // __ / ___/ / ___/ Version 0.9.2
347+ / // __ / ___/ / ___/ Version 0.9.5
348348 _/ // /_/ / / / (__ ) http://www.idris-lang.org/
349349 /___/\__,_/_/ /_/____/ Type :? for help
350350
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.2. The files are available in the \Idris{} distribution,
65+0.9.5. 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/modules.tex+56
@@ -172,3 +172,59 @@ types:
172172\end{SaveVerbatim}
173173\useverb{usetest}
174174
175+\subsection{Parameterised blocks}
176+
177+Groups of functions can be parameterised over a number of arguments using a
178+\texttt{parameters} declaration, for example:
179+
180+\begin{SaveVerbatim}{paramex}
181+
182+parameters (x : Nat, y : Nat)
183+ addAll : Nat -> Nat
184+ addAll z = x + y + z
185+
186+\end{SaveVerbatim}
187+\useverb{paramex}
188+
189+\noindent
190+The effect of a \texttt{parameters} block is to add the declared parameters to every
191+function, type and data constructor within the block. Outside the block, the parameters
192+must be given explicitly:
193+
194+\begin{SaveVerbatim}{addall}
195+
196+*params> :t addAll
197+addAll : Nat -> Nat -> Nat -> Nat
198+
199+\end{SaveVerbatim}
200+\useverb{addall}
201+
202+\noindent
203+Parameters blocks can be nested, and can also include data declarations, in
204+which case the parameters are added explicitly to all type and data
205+constructors. They may also be dependent types with implicit arguments:
206+
207+\begin{SaveVerbatim}{paramdata}
208+
209+parameters (xs : Vect a x, y : Nat)
210+ data Vects : Set -> Set where
211+ MkVects : Vect a y -> Vects a
212+
213+ append : Vects a -> Vect a (x + y)
214+ append (MkVects ys) = xs ++ ys
215+
216+\end{SaveVerbatim}
217+\useverb{paramdata}
218+
219+\noindent
220+To use \texttt{Vects} or \texttt{append} outside the block, we must also
221+give the \texttt{xs} and \texttt{y} arguments. Here, we can use placeholders for
222+the values which can be inferred by the type checker:
223+
224+\begin{SaveVerbatim}{paramuse}
225+
226+*params> show (append _ _ (MkVects [1,2,3] _ [4,5,6]))
227+"[1, 2, 3, 4, 5, 6]" : String
228+
229+\end{SaveVerbatim}
230+\useverb{paramuse}
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.2
85+ / // __ / ___/ / ___/ Version 0.9.5
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.2
105+Idris version 0.9.5
106106-------------------
107107
108108 Command Arguments Purpose
@@ -128,7 +128,7 @@ Idris version 0.9.2
128128$ idris hello.idr
129129 ____ __ _
130130 / _/___/ /____(_)____
131− / // __ / ___/ / ___/ Version 0.9.2
131+ / // __ / ___/ / ___/ Version 0.9.5
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.2) Not be mutually recursive
413+\item (In version 0.9.5) Not be mutually recursive
414414\end{itemize}
415415
416416\noindent
tutorial/typesfuns.tex+20
@@ -225,6 +225,26 @@ reverse {a} xs = revAcc [] xs where
225225\end{SaveVerbatim}
226226\useverb{revwhereb}
227227
228+\noindent
229+As well as functions, \texttt{where} blocks can include local data
230+declarations, such as the following where \texttt{MyLT} is not accessible outside
231+the definition of \texttt{foo}:
232+
233+\begin{SaveVerbatim}{wheredata}
234+
235+foo : Int -> Int
236+foo x = case isLT of
237+ Yes => x*2
238+ No => x*4
239+ where
240+ data MyLT = Yes | No
241+
242+ isLT : MyLT
243+ isLT = if x < 20 then Yes else No
244+
245+\end{SaveVerbatim}
246+\useverb{wheredata}
247+
228248\subsection{Dependent Types}
229249
230250\subsubsection{Vectors}