@@ -56,7 +56,7 @@ library:
57\begin{SaveVerbatim}{natlist}
57\begin{SaveVerbatim}{natlist}
59−data Nat = O | S Nat -- Natural numbers
59+data Nat = Z | S Nat -- Natural numbers
60 -- (zero and successor)
60 -- (zero and successor)
61data List a = Nil | (::) a (List a) -- Polymorphic lists
61data List a = Nil | (::) a (List a) -- Polymorphic lists
@@ -181,9 +181,9 @@ literature. In \Idris{}, vectors are declared as follows:
182\begin{SaveVerbatim}{vect}
182\begin{SaveVerbatim}{vect}
184−data Vect : Type -> Nat -> Type where
184+data Vect : Nat -> Type -> Type where
185− Nil : Vect a O
185+ Nil : Vect Z a
186− (::) : a -> Vect a k -> Vect a (S k)
186+ (::) : a -> Vect k a -> Vect (S k) a
188\end{SaveVerbatim}
188\end{SaveVerbatim}
189\useverb{vect}
189\useverb{vect}
@@ -199,15 +199,15 @@ by type.
199The above declaration creates a family of types, and requires a different form
199The above declaration creates a family of types, and requires a different form
200of declaration from the simple type declarations above. It resembles a Haskell
200of declaration from the simple type declarations above. It resembles a Haskell
201GADT declaration: it explicitly states the type
201GADT declaration: it explicitly states the type
202−of the type constructor \tTC{Vect} --- it takes a type and a \tTC{Nat} as an
202+of the type constructor \tTC{Vect} --- it takes a \tTC{Nat} and a type as
203−argument, where \tTC{Type} stands for the type of types. We say that \tTC{Vect}
203+arguments, 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}.
204+is \emph{indexed} over \tTC{Nat} and \emph{parameterised} by a type.
205The distinction between parameters and indices is that a parameter is fixed
205The distinction between parameters and indices is that a parameter is fixed
206across an entire data structure, whereas an index may vary.
206across an entire data structure, whereas an index may vary.
207Each constructor targets a different part of the family of types. \tDC{Nil} can
207Each constructor targets a different part of the family of types. \tDC{Nil} can
208only be used to construct vectors with zero length, and \tDC{::} to construct
208only be used to construct vectors with zero length, and \tDC{::} to construct
209vectors 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
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})
211combine to make a vector of length \texttt{S k}.
211combine to make a vector of length \texttt{S k}.
213Functions on dependent types such as \tTC{Vect} are declared in the same way
213Functions on dependent types such as \tTC{Vect} are declared in the same way
@@ -218,7 +218,7 @@ library, appends two \tTC{Vect}s:
219\begin{SaveVerbatim}{vapp}
219\begin{SaveVerbatim}{vapp}
221−(++) : Vect A n -> Vect A m -> Vect A (n + m)
221+(++) : Vect n a -> Vect m a -> Vect (n + m) a
222Nil ++ ys = ys
222Nil ++ ys = ys
223(x :: xs) ++ ys = x :: xs ++ ys
223(x :: xs) ++ ys = x :: xs ++ ys
@@ -233,7 +233,7 @@ They are declared as follows in the library:
233\begin{SaveVerbatim}{findecl}
233\begin{SaveVerbatim}{findecl}
235data Fin : Nat -> Type where
235data Fin : Nat -> Type where
236− fO : Fin (S k)
236+ fZ : Fin (S k)
237 fS : Fin k -> Fin (S k)
237 fS : Fin k -> Fin (S k)
239\end{SaveVerbatim}
239\end{SaveVerbatim}
@@ -241,7 +241,7 @@ data Fin : Nat -> Type where
243This declares
243This 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;
245\texttt{fS n} as the
245\texttt{fS n} as the
246\texttt{n+1}th element of a finite set with \texttt{S k} elements.
246\texttt{n+1}th element of a finite set with \texttt{S k} elements.
247\tTC{Fin} is indexed by \tTC{Nat}, which
247\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:
260\begin{SaveVerbatim}{vindex}
260\begin{SaveVerbatim}{vindex}
262−index : Fin n -> Vect a n -> a
262+index : Fin n -> Vect n a -> a
263−index fO (x :: xs) = x
263+index fZ (x :: xs) = x
264index (fS k) (x :: xs) = index k xs
264index (fS k) (x :: xs) = index k xs
266\end{SaveVerbatim}
266\end{SaveVerbatim}
@@ -284,7 +284,7 @@ Let us take a closer look at the type of \texttt{index}:
285\begin{SaveVerbatim}{vindexty}
285\begin{SaveVerbatim}{vindexty}
287−index : Fin n -> Vect a n -> a
287+index : Fin n -> Vect n a -> a
289\end{SaveVerbatim}
289\end{SaveVerbatim}
290\useverb{vindexty}
290\useverb{vindexty}
@@ -297,7 +297,7 @@ arguments to \texttt{index}. The type of \texttt{index} could also be written as
298\begin{SaveVerbatim}{vindeximppl}
298\begin{SaveVerbatim}{vindeximppl}
300−index : {a:_} -> {n:_} -> Fin n -> Vect a n -> a
300+index : {a:_} -> {n:_} -> Fin n -> Vect n a -> a
302\end{SaveVerbatim}
302\end{SaveVerbatim}
303\useverb{vindeximppl}
303\useverb{vindeximppl}
@@ -308,7 +308,7 @@ their types, to be inferred by the machine. These types could also be given expl
309\begin{SaveVerbatim}{vindeximpty}
309\begin{SaveVerbatim}{vindeximpty}
311−index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
311+index : {a:Type} -> {n:Nat} -> Fin n -> Vect n a -> a
313\end{SaveVerbatim}
313\end{SaveVerbatim}
314\useverb{vindeximpty}
314\useverb{vindeximpty}
@@ -316,7 +316,7 @@ index : {a:Type} -> {n:Nat} -> Fin n -> Vect a n -> a
317Implicit arguments, given in braces \texttt{\{\}} in the type signature, are
317Implicit arguments, given in braces \texttt{\{\}} in the type signature, are
318not given in applications of \texttt{index}; their values can be inferred from
318not 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
320appears as a parameter or index in a type signature, but which is otherwise
320appears as a parameter or index in a type signature, but which is otherwise
321free, will be automatically bound as an implicit argument. Implicit arguments
321free, will be automatically bound as an implicit argument. Implicit arguments
322can still be given explicitly in applications, using the syntax
322can still be given explicitly in applications, using the syntax
@@ -335,7 +335,7 @@ the type of \texttt{index} could be declared as:
336\begin{SaveVerbatim}{vindexn}
336\begin{SaveVerbatim}{vindexn}
338−index : (i:Fin n) -> (xs:Vect a n) -> a
338+index : (i:Fin n) -> (xs:Vect n a) -> a
340\end{SaveVerbatim}
340\end{SaveVerbatim}
341\useverb{vindexn}
341\useverb{vindexn}
@@ -359,7 +359,7 @@ example, recall the \texttt{vAdd} function:
360\begin{SaveVerbatim}{vadd}
360\begin{SaveVerbatim}{vadd}
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
363vAdd [] [] = []
363vAdd [] [] = []
364vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
364vAdd (x :: xs) (y :: ys) = x + y :: vAdd xs ys
@@ -450,9 +450,9 @@ to a \texttt{String}:
451\begin{SaveVerbatim}{showvec}
451\begin{SaveVerbatim}{showvec}
453−instance Show a => Show (Vect a n) where
453+instance Show a => Show (Vect n a) where
454 show xs = "[" ++ show' xs ++ "]" where
454 show xs = "[" ++ show' xs ++ "]" where
455− show' : Vect a n -> String
455+ show' : Vect n a -> String
456 show' Nil = ""
456 show' Nil = ""
457 show' (x :: Nil) = show x
457 show' (x :: Nil) = show x
458 show' (x :: xs) = show x ++ ", " ++ show' xs
458 show' (x :: xs) = show x ++ ", " ++ show' xs
@@ -570,7 +570,7 @@ determined by whether the vector was empty or not:
571\begin{SaveVerbatim}{appdep}
571\begin{SaveVerbatim}{appdep}
573−(++) : Vect a n -> Vect a m -> Vect a (n + m)
573+(++) : Vect n a -> Vect m a -> Vect (n + m) a
574(++) {n=O} [] [] = []
574(++) {n=O} [] [] = []
575(++) {n=S k} (x :: xs) ys = x :: xs ++ ys
575(++) {n=S k} (x :: xs) ys = x :: xs ++ ys