@@ -13,19 +13,19 @@ environment by typing \texttt{idris prims.idr}:
1313
1414\begin{SaveVerbatim}{constprims}
1515
16−module prims;
16+module prims
1717
18−x : Int;
19−x = 42;
18+x : Int
19+x = 42
2020
21−foo : String;
22−foo = "Sausage machine";
21+foo : String
22+foo = "Sausage machine"
2323
24−bar : Char;
25−bar = 'Z';
24+bar : Char
25+bar = 'Z'
2626
27−quux : Bool;
28−quux = False;
27+quux : Bool
28+quux = False
2929
3030\end{SaveVerbatim}
3131\useverb{constprims}
@@ -35,8 +35,10 @@ An \Idris{} file consists of an optional module declaration (here
3535however \Idris{} programs can consist of several modules, and the definitions
3636in each module each have their own namespace, as we will discuss shortly) and a
3737collection of declarations and definitions. Each definition must have a type
38−declaration (here, \texttt{x : Int}, \texttt{foo : String}, etc). Each
39−component is separated by a semi-colon.
38+declaration (here, \texttt{x : Int}, \texttt{foo : String}, etc).
39+Indentation is significant --- a new declaration begins at the same leve
40+of indentation as the preceding declaration. Alternatively, declarations
41+may be terminated with a semicolon.
4042
4143A library module \texttt{prelude} is automatically imported by every \Idris{} program,
4244including facilities for IO, arithmetic, data structures and various common
@@ -76,9 +78,9 @@ example, can be declared as follows:
7678
7779\begin{SaveVerbatim}{natlist}
7880
79−data Nat = O | S Nat; -- Natural numbers
80− -- (zero and successor)
81−data List a = Nil | (::) a (List a); -- Polymorphic lists
81+data Nat = O | S Nat -- Natural numbers
82+ -- (zero and successor)
83+data List a = Nil | (::) a (List a) -- Polymorphic lists
8284
8385\end{SaveVerbatim}
8486\useverb{natlist}
@@ -93,7 +95,7 @@ such as this can be added using a fixity declaration, as follows:
9395
9496\begin{SaveVerbatim}{infixcons}
9597
96−infixr 7 :: ;
98+infixr 7 ::
9799
98100\end{SaveVerbatim}
99101\useverb{infixcons}
@@ -124,14 +126,14 @@ defined as follows, again taken from the standard library:
124126\begin{SaveVerbatim}{natfns}
125127
126128-- Unary addition
127−plus : Nat -> Nat -> Nat;
128−plus O y = y;
129−plus (S k) y = S (plus k y);
129+plus : Nat -> Nat -> Nat
130+plus O y = y
131+plus (S k) y = S (plus k y)
130132
131133-- Unary multiplication
132−mult : Nat -> Nat -> Nat;
133−mult O y = O;
134−mult (S k) y = plus y (mult k y);
134+mult : Nat -> Nat -> Nat
135+mult O y = O
136+mult (S k) y = plus y (mult k y)
135137
136138\end{SaveVerbatim}
137139\useverb{natfns}
@@ -186,11 +188,11 @@ accumulates the new, reversed list, and which does not need to be visible global
186188
187189\begin{SaveVerbatim}{revwhere}
188190
189−rev : List a -> List a;
191+rev : List a -> List a
190192rev xs = revAcc [] xs where {
191− revAcc : List a -> List a -> List a;
192− revAcc acc [] = acc;
193− revAcc acc (x :: xs) = revAcc (x :: acc) xs;
193+ revAcc : List a -> List a -> List a
194+ revAcc acc [] = acc
195+ revAcc acc (x :: xs) = revAcc (x :: acc) xs
194196}
195197
196198\end{SaveVerbatim}
@@ -207,9 +209,9 @@ behaviour, the \texttt{a} can be brought into scope as follows:
207209
208210\begin{SaveVerbatim}{revwhereb}
209211
210−rev : List a -> List a;
212+rev : List a -> List a
211213rev {a} xs = revAcc [] xs where {
212− revAcc : List a -> List a -> List a;
214+ revAcc : List a -> List a -> List a
213215 ...
214216}
215217
@@ -228,7 +230,7 @@ we declare vectors as follows:
228230
229231data Vect : Set -> Nat -> Set where
230232 Nil : Vect a O
231− | (::) : a -> Vect a k -> Vect a (S k);
233+ | (::) : a -> Vect a k -> Vect a (S k)
232234
233235\end{SaveVerbatim}
234236\useverb{vect}
@@ -257,9 +259,9 @@ library, appends two \tTC{Vect}s:
257259
258260\begin{SaveVerbatim}{vapp}
259261
260−app : Vect A n -> Vect A m -> Vect A (n + m);
261−app Nil ys = ys;
262−app (x :: xs) ys = x :: app xs ys;
262+app : Vect A n -> Vect A m -> Vect A (n + m)
263+app Nil ys = ys
264+app (x :: xs) ys = x :: app xs ys
263265
264266\end{SaveVerbatim}
265267\useverb{vapp}
@@ -270,9 +272,9 @@ not hold, \Idris{} will not accept the definition. For example:
270272
271273\begin{SaveVerbatim}{vapperr}
272274
273−app : Vect a n -> Vect a m -> Vect a (n + m);
274−app Nil ys = ys;
275−app (x :: xs) ys = x :: app xs xs; -- BROKEN
275+app : Vect a n -> Vect a m -> Vect a (n + m)
276+app Nil ys = ys
277+app (x :: xs) ys = x :: app xs xs -- BROKEN
276278
277279\end{SaveVerbatim}
278280\useverb{vapperr}
@@ -303,7 +305,7 @@ They are declared as follows (again, in the prelude):
303305
304306data Fin : Nat -> Set where
305307 fO : Fin (S k)
306− | fS : Fin k -> Fin (S k);
308+ | fS : Fin k -> Fin (S k)
307309
308310\end{SaveVerbatim}
309311\useverb{findecl}
@@ -321,9 +323,9 @@ is defined in the prelude:
321323
322324\begin{SaveVerbatim}{vlookup}
323325
324−lookup : Fin n -> Vect a n -> a;
325−lookup fO (x :: xs) = x;
326−lookup (fS k) (x :: xs) = lookup k xs;
326+lookup : Fin n -> Vect a n -> a
327+lookup fO (x :: xs) = x
328+lookup (fS k) (x :: xs) = lookup k xs
327329
328330\end{SaveVerbatim}
329331\useverb{vlookup}
@@ -384,7 +386,7 @@ declared the type of \texttt{lookup} as:
384386
385387\begin{SaveVerbatim}{vlookupn}
386388
387−lookup : (i:Fin n) -> (xs:Vect a n) -> a;
389+lookup : (i:Fin n) -> (xs:Vect a n) -> a
388390
389391\end{SaveVerbatim}
390392\useverb{vlookupn}
@@ -406,7 +408,7 @@ definition, which defines a predicate on vectors:
406408
407409data Elem : a -> (Vect a n) -> Set where
408410 here : {x:a} -> {xs:Vect a n} -> Elem x (x :: xs)
409− | there : {x,y:a} -> {xs:Vect a n} -> Elem x xs -> Elem x (y :: xs);
411+ | there : {x,y:a} -> {xs:Vect a n} -> Elem x xs -> Elem x (y :: xs)
410412
411413\end{SaveVerbatim}
412414\useverb{elem}
@@ -419,11 +421,11 @@ or \texttt{there}, in the tail of the vector. For example:
419421
420422\begin{SaveVerbatim}{testelem}
421423
422−testVec : Vect Int 4;
423−testVec = 3 :: 4 :: 5 :: 6 :: VNil;
424+testVec : Vect Int 4
425+testVec = 3 :: 4 :: 5 :: 6 :: VNil
424426
425−inVect : Elem 5 testVec;
426−inVect = there (there here);
427+inVect : Elem 5 testVec
428+inVect = there (there here)
427429
428430\end{SaveVerbatim}
429431\useverb{testelem}
@@ -438,7 +440,7 @@ ordering of any implicit arguments which can appear within the block:
438440using (x:a, y:a, xs:Vect a n) {
439441 data Elem : a -> (Vect a n) -> Set where
440442 here : Elem x (x :: xs)
441− | there : Elem x xs -> Elem x (y :: xs);
443+ | there : Elem x xs -> Elem x (y :: xs)
442444}
443445
444446\end{SaveVerbatim}
@@ -454,7 +456,7 @@ encapsulated in the type \texttt{IO}:
454456
455457\begin{SaveVerbatim}{ioty}
456458
457−data IO a; -- IO operation returning a value of type a
459+data IO a -- IO operation returning a value of type a
458460
459461\end{SaveVerbatim}
460462\useverb{ioty}
@@ -467,8 +469,8 @@ program:
467469
468470\begin{SaveVerbatim}{main}
469471
470−main : IO ();
471−main = putStrLn "Hello world";
472+main : IO ()
473+main = putStrLn "Hello world"
472474
473475\end{SaveVerbatim}
474476\useverb{main}
@@ -479,8 +481,8 @@ outputs a string without a newline:
479481
480482\begin{SaveVerbatim}{putstr}
481483
482−putStrLn : String -> IO ();
483−putStr : String -> IO ();
484+putStrLn : String -> IO ()
485+putStr : String -> IO ()
484486
485487\end{SaveVerbatim}
486488
@@ -488,7 +490,7 @@ We can also read strings from user input:
488490
489491\begin{SaveVerbatim}{getline}
490492
491−getLine : IO String;
493+getLine : IO String
492494
493495\end{SaveVerbatim}
494496\useverb{getline}
@@ -499,17 +501,17 @@ writing files, including:
499501
500502\begin{SaveVerbatim}{fileops}
501503
502−data File; -- abstract
503−data Mode = Read | Write | ReadWrite;
504+data File -- abstract
505+data Mode = Read | Write | ReadWrite
504506
505−openFile : String -> Mode -> IO File;
506−closeFile : File -> IO ();
507+openFile : String -> Mode -> IO File
508+closeFile : File -> IO ()
507509
508−fread : File -> IO String;
509−fwrite : File -> String -> IO ();
510−feof : File -> IO Bool;
510+fread : File -> IO String
511+fwrite : File -> String -> IO ()
512+feof : File -> IO Bool
511513
512−readFile : String -> IO String;
514+readFile : String -> IO String
513515
514516\end{SaveVerbatim}
515517\useverb{fileops}
@@ -525,11 +527,11 @@ operations with \texttt{do} notation:
525527
526528\begin{SaveVerbatim}{greet}
527529
528−greet : IO ();
529−greet = do { putStr "What is your name? ";
530− name <- getLine;
531− putStrLn ("Hello " ++ name);
532− };
530+greet : IO ()
531+greet = do { putStr "What is your name? "
532+ name <- getLine
533+ putStrLn ("Hello " ++ name)
534+ }
533535
534536\end{SaveVerbatim}
535537\useverb{greet}
@@ -544,7 +546,7 @@ operation:
544546
545547\begin{SaveVerbatim}{return}
546548
547−return : a -> IO a;
549+return : a -> IO a
548550
549551\end{SaveVerbatim}
550552\useverb{return}
@@ -566,11 +568,11 @@ We have already seen the \texttt{List} and \texttt{Vect} data types:
566568
567569\begin{SaveVerbatim}{listvec}
568570
569−data List a = Nil | (::) a (List a);
571+data List a = Nil | (::) a (List a)
570572
571573data Vect : Set -> Nat -> Set where
572574 Nil : Vect a O
573− | (::) : a -> Vect a k -> Vect a (S k);
575+ | (::) : a -> Vect a k -> Vect a (S k)
574576
575577\end{SaveVerbatim}
576578\useverb{listvec}
@@ -594,13 +596,13 @@ and applies a function to every element of the list or vector.
594596
595597\begin{SaveVerbatim}{map}
596598
597−map : (a -> b) -> List a -> List b;
598−map f [] = [];
599−map f (x :: xs) = f x :: map f xs;
599+map : (a -> b) -> List a -> List b
600+map f [] = []
601+map f (x :: xs) = f x :: map f xs
600602
601−map : (a -> b) -> Vect a n -> Vect b n;
602−map f [] = [];
603−map f (x :: xs) = f x :: map f xs;
603+map : (a -> b) -> Vect a n -> Vect b n
604+map f [] = []
605+map f (x :: xs) = f x :: map f xs
604606
605607\end{SaveVerbatim}
606608\useverb{map}
@@ -610,11 +612,11 @@ For example, to double every element in a vector of integers:
610612
611613\begin{SaveVerbatim}{dvect}
612614
613−intVec : Vect Int 5;
614−intVec = [1, 2, 3, 4, 5];
615+intVec : Vect Int 5
616+intVec = [1, 2, 3, 4, 5]
615617
616−double : Int -> Int;
617−double x = x * 2;
618+double : Int -> Int
619+double x = x * 2
618620
619621\end{SaveVerbatim}
620622\useverb{dvect}
@@ -679,7 +681,7 @@ or there isn't:
679681
680682\begin{SaveVerbatim}{maybe}
681683
682−data Maybe a = Just a | Nothing;
684+data Maybe a = Just a | Nothing
683685
684686\end{SaveVerbatim}
685687\useverb{maybe}
@@ -691,10 +693,10 @@ bounds error:
691693
692694\begin{SaveVerbatim}{lookuplist}
693695
694−list_lookup : Nat -> List a -> Maybe a;
695−list_lookup _ Nil = Nothing;
696−list_lookup O (x :: xs) = Just x;
697−list_lookup (S k) (x :: xs) = list_lookup k xs;
696+list_lookup : Nat -> List a -> Maybe a
697+list_lookup _ Nil = Nothing
698+list_lookup O (x :: xs) = Just x
699+list_lookup (S k) (x :: xs) = list_lookup k xs
698700
699701\end{SaveVerbatim}
700702\useverb{lookuplist}
@@ -705,7 +707,7 @@ either by applying a function to the value, if there is one, or by providing a d
705707
706708\begin{SaveVerbatim}{maybefn}
707709
708−maybe : Maybe a -> |(default:b) -> (a -> b) -> b;
710+maybe : Maybe a -> |(default:b) -> (a -> b) -> b
709711
710712\end{SaveVerbatim}
711713\useverb{maybefn}
@@ -724,7 +726,7 @@ Values can be paired with the following built-in data type:
724726
725727\begin{SaveVerbatim}{mkpair}
726728
727−data Pair a b = MkPair a b;
729+data Pair a b = MkPair a b
728730
729731\end{SaveVerbatim}
730732\useverb{mkpair}
@@ -736,11 +738,11 @@ Tuples can contain an arbitrary number of values, represented as nested pairs:
736738
737739\begin{SaveVerbatim}{tuple}
738740
739−fred : (String, Int);
740−fred = ("Fred", 42);
741+fred : (String, Int)
742+fred = ("Fred", 42)
741743
742−jim : (String, Int, String);
743−jim = ("Jim", 25, "Cambridge");
744+jim : (String, Int, String)
745+jim = ("Jim", 25, "Cambridge")
744746
745747\end{SaveVerbatim}
746748\useverb{tuple}
@@ -753,7 +755,7 @@ the value of the first element:
753755\begin{SaveVerbatim}{sigma}
754756
755757data Exists : (A : Set) -> (P : A -> Set) -> Set where
756− Ex_intro : {P : A -> Set} -> (a : A) -> P a -> Exists A P;
758+ Ex_intro : {P : A -> Set} -> (a : A) -> P a -> Exists A P
757759
758760\end{SaveVerbatim}
759761\useverb{sigma}
@@ -766,8 +768,8 @@ constructs a value of this type. For example, we can pair a number with a
766768
767769\begin{SaveVerbatim}{dvec}
768770
769−vec : (n : Nat ** Vect Int n);
770−vec = (2 ** [3, 4]);
771+vec : (n : Nat ** Vect Int n)
772+vec = (2 ** [3, 4])
771773
772774\end{SaveVerbatim}
773775\useverb{dvec}
@@ -780,8 +782,8 @@ written as:
780782
781783\begin{SaveVerbatim}{dvec1}
782784
783−vec : (n : Nat ** Vect Int n);
784−vec = (_ ** [3, 4]);
785+vec : (n : Nat ** Vect Int n)
786+vec = (_ ** [3, 4])
785787
786788\end{SaveVerbatim}
787789\useverb{dvec1}
@@ -792,8 +794,8 @@ again, it can be inferred:
792794
793795\begin{SaveVerbatim}{dvec2}
794796
795−vec : (n ** Vect Int n);
796−vec = (_ ** [3, 4]);
797+vec : (n ** Vect Int n)
798+vec = (_ ** [3, 4])
797799
798800\end{SaveVerbatim}
799801\useverb{dvec2}
@@ -806,7 +808,7 @@ length of the resulting vector will be:
806808
807809\begin{SaveVerbatim}{vfilter}
808810
809−filter : (a -> Bool) -> Vect a n -> (p ** Vect a p);
811+filter : (a -> Bool) -> Vect a n -> (p ** Vect a p)
810812
811813\end{SaveVerbatim}
812814\useverb{vfilter}
@@ -816,7 +818,7 @@ If the \texttt{Vect} is empty, the result is easy:
816818
817819\begin{SaveVerbatim}{vfilternil}
818820
819−vfilter p VNil = (_ , []);
821+vfilter p VNil = (_ , [])
820822
821823\end{SaveVerbatim}
822824\useverb{vfilternil}
@@ -830,7 +832,7 @@ notation. with allows pattern matching on intermediate values:
830832\begin{SaveVerbatim}{vfiltercons}
831833
832834filter p (x :: xs) with filter p xs {
833− | (_ , xs') = if (p x) then (_ , x :: xs') else (_ , xs');
835+ | (_ , xs') = if (p x) then (_ , x :: xs') else (_ , xs')
834836}
835837
836838\end{SaveVerbatim}
@@ -847,9 +849,9 @@ Intermediate values can be calculated using \texttt{let} bindings:
847849
848850\begin{SaveVerbatim}{letb}
849851
850−mirror : List a -> List a;
852+mirror : List a -> List a
851853mirror xs = let xs' = rev xs in
852− app xs xs';
854+ app xs xs'
853855
854856\end{SaveVerbatim}
855857\useverb{letb}
@@ -860,11 +862,11 @@ fields from a record as follows, as well as by pattern matching at the top level
860862
861863\begin{SaveVerbatim}{letp}
862864
863−data Person = MkPerson String Int;
865+data Person = MkPerson String Int
864866
865−showPerson : Person -> String;
867+showPerson : Person -> String
866868showPerson p = let MkPerson name age = p in
867− name ++ " is " ++ show age ++ " years old";
869+ name ++ " is " ++ show age ++ " years old"
868870
869871\end{SaveVerbatim}
870872\useverb{letp}
@@ -891,9 +893,9 @@ follows:
891893
892894\begin{SaveVerbatim}{triples}
893895
894−pythag : Int -> List (Int, Int, Int);
896+pythag : Int -> List (Int, Int, Int)
895897pythag n = [ (x, y, z) | z <- [1..n], y <- [1..z], x <- [1..y],
896− x*x + y*y == z*z ];
898+ x*x + y*y == z*z ]
897899
898900\end{SaveVerbatim}
899901\useverb{triples}
@@ -913,10 +915,10 @@ The following function, for example, splits a string into two at a given charact
913915
914916\begin{SaveVerbatim}{split}
915917
916−splitAt : Char -> String -> (String, String);
918+splitAt : Char -> String -> (String, String)
917919splitAt c x = case break (== c) x of {
918920 (x, y) => (x, strTail y)
919− };
921+ }
920922
921923\end{SaveVerbatim}
922924\useverb{split}
@@ -934,11 +936,11 @@ looks up an index and returns a default value if the index is out of bounds:
934936
935937\begin{SaveVerbatim}{listlookup}
936938
937−lookup_default : Nat -> List a -> a -> a;
939+lookup_default : Nat -> List a -> a -> a
938940lookup_default i xs def = case list_lookup i xs of {
939941 Nothing => def
940942 | Just x => x
941− };
943+ }
942944
943945\end{SaveVerbatim}
944946\useverb{listlookup}