@@ -13,8 +13,7 @@ manipulation, and ``Ptr`` which represents foreign pointers. There are
1313also several data types declared in the library, including ``Bool``,
1414with values ``True`` and ``False``. We can declare some constants with
1515these types. Enter the following into a file ``Prims.idr`` and load it
16−into the Idris interactive environment by typing ``idris
17−Prims.idr``:
16+into the Idris interactive environment by typing ``idris Prims.idr``:
1817
1918.. code-block:: idris
2019
@@ -38,7 +37,7 @@ collection of declarations and definitions. In this example no imports
3837have been specified. However Idris programs can consist of several
3938modules and the definitions in each module each have their own
4039namespace. This is discussed further in Section
41−:ref:`sect-namespaces`). When writing Idris programs both the order in which
40+:ref:`sect-namespaces`. When writing Idris programs both the order in which
4241definitions are given and indentation are significant. Functions and
4342data types must be defined before use, incidentally each definition must
4443have a type declaration, for example see ``x : Int``, ``foo :
@@ -343,7 +342,7 @@ Vectors
343342
344343A standard example of a dependent data type is the type of “lists with
345344length”, conventionally called vectors in the dependent type
346−literature. They are available as part of the Idris library, by
345+literature. They are available as part of the Idris library, by
347346importing ``Data.Vect``, or we can declare them as follows:
348347
349348.. code-block:: idris
@@ -521,8 +520,8 @@ help document a function by making the purpose of an argument more
521520clear.
522521
523522Furthermore, ``{}`` can be used to pattern match on the left hand side, i.e.
524−``{var = pat}`` gets an implicit variable and attempts to pattern match on "pat";
525−For example :
523+``{var = pat}`` gets an implicit variable and attempts to pattern match on “pat”;
524+For example:
526525
527526.. code-block:: idris
528527
@@ -559,7 +558,6 @@ vector. For example:
559558 inVect : IsElem 5 Main.testVec
560559 inVect = There (There Here)
561560
562−
563561.. important:: Implicit Arguments and Scope
564562
565563 Within the type signature the typechecker will treat all variables
@@ -569,7 +567,6 @@ vector. For example:
569567 ``testVec``. In the example above, we have assumed that the code
570568 lives within the ``Main`` module.
571569
572−
573570If the same implicit arguments are being used a lot, it can make a
574571definition difficult to read. To avoid this problem, a ``using`` block
575572gives the types and ordering of any implicit arguments which can
@@ -582,15 +579,13 @@ appear within the block:
582579 Here : IsElem x (x :: xs)
583580 There : IsElem x xs -> IsElem x (y :: xs)
584581
585−
586−
587582Note: Declaration Order and ``mutual`` blocks
588583~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
589584
590585In general, functions and data types must be defined before use, since
591586dependent types allow functions to appear as part of types, and type
592587checking can rely on how particular functions are defined (though this
593−is only true of total functions; see Section :ref:`sect-totality`)).
588+is only true of total functions; see Section :ref:`sect-totality`).
594589However, this restriction can be relaxed by using a ``mutual`` block,
595590which allows data types and functions to be defined simultaneously:
596591
@@ -673,7 +668,7 @@ Note that several of these return ``Either``, since they may fail.
673668I/O programs will typically need to sequence actions, feeding the
674669output of one computation into the input of the next. ``IO`` is an
675670abstract type, however, so we can’t access the result of a computation
676−directly. Instead, we sequence operations with ``do`` notation:
671+directly. Instead, we sequence operations with ``do`` notation:
677672
678673.. code-block:: idris
679674
@@ -713,7 +708,7 @@ not always the best approach. Consider the following function:
713708
714709This function uses one of the ``t`` or ``e`` arguments, but not both
715710(in fact, this is used to implement the ``if...then...else`` construct
716−as we will see later. We would prefer if *only* the argument which was
711+as we will see later). We would prefer if *only* the argument which was
717712used was evaluated. To achieve this, Idris provides a ``Lazy``
718713data type, which allows evaluation to be suspended:
719714
@@ -797,7 +792,7 @@ infinite loop and cause a stack overflow.
797792To fix this we must add explicit ``Inf`` declarations to the constructor
798793parameter types, since codata will not add it to constructor parameters of a
799794**different** type from the one being defined. For example, the following
800−outputs "1".
795+outputs ``1``.
801796
802797.. code-block:: idris
803798
@@ -902,7 +897,7 @@ For more details of the functions available on ``List`` and
902897
903898- ``libs/base/Data/VectType.idr``
904899
905−Functions include filtering, appending, reversing, and so on.
900+Functions include filtering, appending, reversing, and so on.
906901
907902Aside: Anonymous functions and operator sections
908903~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -999,7 +994,7 @@ Dependent Pairs
999994---------------
1000995
1001996Dependent pairs allow the type of the second element of a pair to depend
1002−on the value of the first element.
997+on the value of the first element:
1003998
1004999.. code-block:: idris
10051000
@@ -1009,7 +1004,7 @@ on the value of the first element.
10091004Again, there is syntactic sugar for this. ``(a : A ** P)`` is the type
10101005of a pair of A and P, where the name ``a`` can occur inside ``P``.
10111006``( a ** p )`` constructs a value of this type. For example, we can
1012−pair a number with a ``Vect`` of a particular length.
1007+pair a number with a ``Vect`` of a particular length:
10131008
10141009.. code-block:: idris
10151010
@@ -1017,7 +1012,7 @@ pair a number with a ``Vect`` of a particular length.
10171012 vec = (2 ** [3, 4])
10181013
10191014If you like, you can write it out the long way, the two are precisely
1020−equivalent.
1015+equivalent:
10211016
10221017.. code-block:: idris
10231018
@@ -1070,7 +1065,7 @@ intermediate values:
10701065
10711066We will see more on ``with`` notation later.
10721067
1073−Dependent pairs are sometimes referred to as “sigma types”.
1068+Dependent pairs are sometimes referred to as “Sigma types”.
10741069
10751070Records
10761071-------
@@ -1080,7 +1075,7 @@ Records
10801075automatically generating field access and update functions. Unlike
10811076the syntax used for data structures, records in Idris follow a
10821077different syntax to that seen with Haskell. For example, we can
1083−represent a person's name and age in a record:
1078+represent a person’s name and age in a record:
10841079
10851080.. code-block:: idris
10861081
@@ -1092,12 +1087,11 @@ represent a person's name and age in a record:
10921087 fred : Person
10931088 fred = MkPerson "Fred" "Joe" "Bloggs" 30
10941089
1095−
10961090The constructor name is provided using the ``constructor`` keyword,
10971091and the *fields* are then given which are in an indented block
10981092following the `where` keyword (here, ``firstName``, ``middleName``,
10991093``lastName``, and ``age``). You can declare multiple fields on a
1100−single line, provided that they have the same type. The field names
1094+single line, provided that they have the same type. The field names
11011095can be used to access the field values:
11021096
11031097::
@@ -1171,7 +1165,7 @@ syntax:
11711165 record { a->b->c = val } x
11721166
11731167This returns a new record, with the field accessed by the path
1174−``a->b->c`` set to ``val``. The syntax is first class, i.e. ``record {
1168+``a->b->c`` set to ``val``. The syntax is first class, i.e. ``record {
11751169a->b->c = val }`` itself has a function type. Symmetrically, the field
11761170can also be accessed with the following syntax:
11771171
@@ -1196,12 +1190,10 @@ name. For example, a pair type could be defined as follows:
11961190 fst : a
11971191 snd : b
11981192
1199−
12001193Using the ``class`` record from earlier, the size of the class can be
12011194restricted using a ``Vect`` and the size included in the type by parameterising
12021195the record with the size. For example:
12031196
1204−
12051197.. code-block:: idris
12061198
12071199 record SizedClass (size : Nat) where
@@ -1214,7 +1206,7 @@ function from earlier, since that would change the size of the class. A
12141206function to add a student must now specify in the type that the
12151207size of the class has been increased by one. As the size is specified
12161208using natural numbers, the new value can be incremented using the
1217−``S`` constructor.
1209+``S`` constructor:
12181210
12191211.. code-block:: idris
12201212
@@ -1327,7 +1319,7 @@ matching ``let`` and lambda bindings. It will *only* work if:
13271319- Each branch *matches* a value of the same type, and *returns* a
13281320 value of the same type.
13291321
1330−- The type of the result is "known". i.e. the type of the expression
1322+- The type of the result is “known”. i.e. the type of the expression
13311323 can be determined *without* type checking the ``case``-expression
13321324 itself.
13331325
@@ -1337,7 +1329,7 @@ Totality
13371329Idris distinguishes between *total* and *partial* functions.
13381330A total function is a function that either:
13391331
1340−+ Terminates for all possible inputs, or
1332++ Terminates for all possible inputs, or
13411333+ Produces a non-empty, finite, prefix of a possibly infinite result
13421334
13431335If a function is total, we can consider its type a precise description of what
@@ -1345,12 +1337,12 @@ that function will do. For example, if we have a function with a return
13451337type of ``String`` we know something different, depending on whether or not
13461338it's total:
13471339
1348−+ If it's total, it will return a value of type ``String`` in finite time
1340++ If it's total, it will return a value of type ``String`` in finite time;
13491341+ If it's partial, then as long as it doesn't crash or enter an infinite loop,
13501342 it will return a ``String``.
13511343
13521344Idris makes this distinction so that it knows which functions are safe to
1353−evaluate while type checking (as we've seen with :ref:`sect-fctypes`). After all,
1345+evaluate while type checking (as we've seen with :ref:`sect-fctypes`). After all,
13541346if it tries to evaluate a function during type checking which doesn't
13551347terminate, then type checking won't terminate!
13561348Therefore, only total functions will be evaluated during type checking.