@@ -166,23 +166,14 @@ Indentation is significant --- functions in the \texttt{where} block must be ind
166further than the outer function.
166further than the outer function.
168\textbf{Remark (scope):}
168\textbf{Remark (scope):}
169−Any names which are visible in the outer scope are also visible in the \texttt{where}
169+Any names which are visible in the outer scope are also visible in the
170−clause (unless they have been redefined, such as \texttt{xs} here).
170+\texttt{where} clause (unless they are redefined in the \texttt{where} clause,
171−\emph{However}, names which appear in the type are \emph{not} automatically
171+such as \texttt{xs} here). A name which appears only in the type will be in
172−in scope. In particular,
172+scope in the \texttt{where} clause if it is a \remph{parameter} to one of the
173−in the above example, the \texttt{a} in the top level type and the \texttt{a} in the
173+types, i.e. it is fixed across the entire structure. In particular, this means
174−auxiliary definition \texttt{revAcc} are \emph{not} the same. If this is the required
174+that the \texttt{a} in the definition of \texttt{reverse} above is the
175−behaviour, the \texttt{a} can be brought into scope as follows:
175+\remph{same} \texttt{a} as in the definition of \texttt{revAcc}, as \texttt{a}
176−
176+is a parameter of \texttt{List}.
177−\begin{SaveVerbatim}{revwhereb}
179−reverse : List a -> List a
180−reverse {a} xs = revAcc [] xs where
181− revAcc : List a -> List a -> List a
187\subsubsection{Dependent Types}
178\subsubsection{Dependent Types}
@@ -210,9 +201,11 @@ from the simple type declarations above. It resembles a Haskell GADT
210declaration: it explicitly states the type
201declaration: it explicitly states the type
211of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
202of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
212argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
203argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
213−is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}. Each
204+is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}.
205+The distinction between parameters and indices is that a parameter is fixed
206+across an entire structure, whereas an index may vary.
214−constructor targets a different part of the family of types. \tDC{Nil} can only
207+Each constructor targets a different part of the family of types. \tDC{Nil} can
215−be used to construct vectors with zero length, and \tDC{::} to construct
208+only be used to construct vectors with zero length, and \tDC{::} to construct
216vectors with non-zero length. The type of \tDC{::} states explicitly that an element
209vectors with non-zero length. The type of \tDC{::} states explicitly that an element
217of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
210of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
218combine to make a vector of length \texttt{S k}.
211combine to make a vector of length \texttt{S k}.
@@ -425,7 +418,7 @@ to a \texttt{String}:
426instance Show a => Show (Vect a n) where
419instance Show a => Show (Vect a n) where
427 show xs = "[" ++ show' xs ++ "]" where
420 show xs = "[" ++ show' xs ++ "]" where
428− show' : Vect a n' -> String
421+ show' : Vect a n -> String
429 show' Nil = ""
422 show' Nil = ""
430 show' (x :: Nil) = show x
423 show' (x :: Nil) = show x
431 show' (x :: xs) = show x ++ ", " ++ show' xs
424 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -433,15 +426,16 @@ instance Show a => Show (Vect a n) where
433\end{SaveVerbatim}
426\end{SaveVerbatim}
434\useverb{showvec}
427\useverb{showvec}
436−\noindent
429+%\noindent
437−\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
430+%\textbf{Remark: } The type of the auxiliary function \texttt{show'} is
438−important. The type variables \texttt{a} and \texttt{n} which are part of the
431+%important. The type variables \texttt{a} and \texttt{n} which are part of the
439−instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
432+%instance declaration for \texttt{Show (Vect a n)} are fixed across the entire
440−instance declaration. As a result, \texttt{a} need not be constrained
433+%instance declaration. As a result, \texttt{a} need not be constrained
441−again. Furthermore, it means that if \texttt{n} is used again in the type, it refers
434+%again. Furthermore, it means that if \texttt{n} is used again in the type, it refers
442−to the (fixed) length of the outermost list \texttt{xs}. Therefore,
435+%to the (fixed) length of the outermost list \texttt{xs}. Therefore,
443−there is a different name for the length \texttt{n'} in \texttt{show'}.
436+%there is a different name for the length \texttt{n'} in \texttt{show'}.
445Like Haskell type classes, default definitions can be given in the class declaration.
439Like Haskell type classes, default definitions can be given in the class declaration.
446Otherwise, all methods must be given in an instance. For example, there is an
440Otherwise, all methods must be given in an instance. For example, there is an
447\texttt{Eq} class:
441\texttt{Eq} class: