@@ -56,7 +56,7 @@ library:
5656
5757\begin{SaveVerbatim}{natlist}
5858
59−data Nat = O | S Nat -- Natural numbers
59+data Nat = Z | S Nat -- Natural numbers
6060 -- (zero and successor)
6161data List a = Nil | (::) a (List a) -- Polymorphic lists
6262
@@ -181,9 +181,9 @@ literature. In \Idris{}, vectors are declared as follows:
181181
182182\begin{SaveVerbatim}{vect}
183183
184−data Vect : Type -> Nat -> Type where
185− Nil : Vect a O
186− (::) : a -> Vect a k -> Vect a (S k)
184+data Vect : Nat -> Type -> Type where
185+ Nil : Vect Z a
186+ (::) : a -> Vect k a -> Vect (S k) a
187187
188188\end{SaveVerbatim}
189189\useverb{vect}
@@ -199,15 +199,15 @@ by type.
199199The above declaration creates a family of types, and requires a different form
200200of declaration from the simple type declarations above. It resembles a Haskell
201201GADT declaration: it explicitly states the type
202−of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
203−argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
204−is \emph{parameterised} by a type, and \emph{indexed} over \tTC{Nat}.
202+of the type constructor \tTC{Vect} --- it takes a \tTC{Nat} and a type as
203+arguments, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
204+is \emph{indexed} over \tTC{Nat} and \emph{parameterised} by a type.
205205The distinction between parameters and indices is that a parameter is fixed
206206across an entire data structure, whereas an index may vary.
207207Each constructor targets a different part of the family of types. \tDC{Nil} can
208208only be used to construct vectors with zero length, and \tDC{::} to construct
209209vectors with non-zero length. The type of \tDC{::} states explicitly that an element
210−of type \texttt{a} and a tail of type \texttt{Vect a k} (i.e., a vector of length \texttt{k})
210+of type \texttt{a} and a tail of type \texttt{Vect k a} (i.e., a vector of length \texttt{k})
211211combine to make a vector of length \texttt{S k}.
212212
213213Functions on dependent types such as \tTC{Vect} are declared in the same way
@@ -218,7 +218,7 @@ library, appends two \tTC{Vect}s:
218218
219219\begin{SaveVerbatim}{vapp}
220220
221−(++) : Vect A n -> Vect A m -> Vect A (n + m)
221+(++) : Vect n a -> Vect m a -> Vect (n + m) a
222222Nil ++ ys = ys
223223(x :: xs) ++ ys = x :: xs ++ ys
224224
@@ -233,7 +233,7 @@ They are declared as follows in the library:
233233\begin{SaveVerbatim}{findecl}
234234
235235data Fin : Nat -> Type where
236− fO : Fin (S k)
236+ fZ : Fin (S k)
237237 fS : Fin k -> Fin (S k)
238238
239239\end{SaveVerbatim}
@@ -241,7 +241,7 @@ data Fin : Nat -> Type where
241241
242242\noindent
243243This declares
244−\tDC{fO} as the zeroth element of a finite set with \texttt{S k} elements;
244+\tDC{fZ} as the zeroth element of a finite set with \texttt{S k} elements;
245245\texttt{fS n} as the
246246\texttt{n+1}th element of a finite set with \texttt{S k} elements.
247247\tTC{Fin} is indexed by \tTC{Nat}, which
@@ -259,8 +259,8 @@ by a bounded index given as a \tTC{Fin n}, is defined in the library:
259259
260260\begin{SaveVerbatim}{vindex}
261261
262−index : Fin n -> Vect a n -> a
263−index fO (x :: xs) = x
262+index : Fin n -> Vect n a -> a
263+index fZ (x :: xs) = x
264264index (fS k) (x :: xs) = index k xs
265265
266266\end{SaveVerbatim}
@@ -284,7 +284,7 @@ Let us take a closer look at the type of \texttt{index}:
284284
285285\begin{SaveVerbatim}{vindexty}
286286
287−index : Fin n -> Vect a n -> a
287+index : Fin n -> Vect n a -> a
288288
289289\end{SaveVerbatim}
290290\useverb{vindexty}
@@ -297,7 +297,7 @@ arguments to \texttt{index}. The type of \texttt{index} could also be written as
297297
298298\begin{SaveVerbatim}{vindeximppl}
299299
300−index : {a:_} -> {n:_} -> Fin n -> Vect a n -> a
300+index : {a:_} -> {n:_} -> Fin n -> Vect n a -> a
301301
302302\end{SaveVerbatim}
303303\useverb{vindeximppl}
@@ -308,7 +308,7 @@ their types, to be inferred by the machine. These types could also be given expl
308308
309309\begin{SaveVerbatim}{vindeximpty}
310310
311−index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
311+index : {a:Type} -> {n:Nat} -> Fin n -> Vect n a -> a
312312
313313\end{SaveVerbatim}
314314\useverb{vindeximpty}
@@ -316,7 +316,7 @@ index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
316316\noindent
317317Implicit arguments, given in braces \texttt{\{\}} in the type signature, are
318318not given in applications of \texttt{index}; their values can be inferred from
319−the types of the \texttt{Fin n} and \texttt{Vect a n} arguments. Any name which
319+the types of the \texttt{Fin n} and \texttt{Vect n a} arguments. Any name which
320320appears as a parameter or index in a type signature, but which is otherwise
321321free, will be automatically bound as an implicit argument. Implicit arguments
322322can still be given explicitly in applications, using the syntax
@@ -335,7 +335,7 @@ the type of \texttt{index} could be declared as:
335335
336336\begin{SaveVerbatim}{vindexn}
337337
338−index : (i:Fin n) -> (xs:Vect a n) -> a
338+index : (i:Fin n) -> (xs:Vect n a) -> a
339339
340340\end{SaveVerbatim}
341341\useverb{vindexn}
@@ -359,7 +359,7 @@ example, recall the \texttt{vAdd} function:
359359
360360\begin{SaveVerbatim}{vadd}
361361
362−total vAdd : Num a => Vect a n -> Vect a n -> Vect a n
362+total vAdd : Num a => Vect n a -> Vect n a -> Vect n a
363363vAdd [] [] = []
364364vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
365365
@@ -450,9 +450,9 @@ to a \texttt{String}:
450450
451451\begin{SaveVerbatim}{showvec}
452452
453−instance Show a => Show (Vect a n) where
453+instance Show a => Show (Vect n a) where
454454 show xs = "[" ++ show' xs ++ "]" where
455− show' : Vect a n -> String
455+ show' : Vect n a -> String
456456 show' Nil = ""
457457 show' (x :: Nil) = show x
458458 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -570,7 +570,7 @@ determined by whether the vector was empty or not:
570570
571571\begin{SaveVerbatim}{appdep}
572572
573−(++) : Vect a n -> Vect a m -> Vect a (n + m)
573+(++) : Vect n a -> Vect m a -> Vect (n + m) a
574574(++) {n=O} [] [] = []
575575(++) {n=S k} (x :: xs) ys = x :: xs ++ ys
576576