on master help sign in
Merge pull request #2151 from jfdm/doc/fixes

Fixes for Idris Tutorial User Docs

commit72f438679a4d9a4745014eb81ea52f5888588a7a authorJan de Muijnck-Hughes <jfdm@users.noreply.github.com> dateThu 16 Apr 2015, 09:46 (12 years ago) parentb4d23ebdb8116b
5 files changed+72−70
docs/tutorial/introduction.rst+10−10 docs/tutorial/modules.rst+14−12 docs/tutorial/starting.rst+9−13 docs/tutorial/typesfuns.rst+37−33 docs/tutorial/views.rst+2−2
docs/tutorial/introduction.rst+10−10
@@ -25,11 +25,12 @@ lists of a given length [1]_, ``Vect n a``, where ``a`` is the element
2525type and ``n`` is the length of the list and can be an arbitrary term.
2626
2727When types can contain values, and where those values describe
28−properties (e.g. the length of a list) the type of a function can
29−begin to describe its own properties. For example, concatenating two
30−lists has the property that the resulting list’s length is the sum of
31−the lengths of the two input lists. We can therefore give the
32−following type to the ``app`` function, which concatenates vectors:
28+properties, for example the length of a list, the type of a function
29+can begin to describe its own properties. Take for example the
30+concatenatation of two lists. This operation has the property that the
31+resulting list's length is the sum of the lengths of the two input
32+lists. We can therefore give the following type to the ``app``
33+function, which concatenates vectors:
3334
3435.. code-block:: idris
3536
@@ -58,11 +59,10 @@ Example Code
5859============
5960
6061This tutorial includes some example code, which has been tested with
61−Idris version . The files are available in the Idris
62−distribution, and provided along side the tutorial source, so that you
63−can try them out easily, under ``tutorial/examples``. However, it is
64−strongly recommended that you can type them in yourself, rather than
65−simply loading and reading them.
62+against Idris. These files are available with the Idris distribution,
63+so that you can try them out easily. They can be found under
64+``samples``. It is, however, strongly recommended that you type
65+them in yourself, rather than simply loading and reading them.
6666
6767.. [1]
6868 Typically, and perhaps confusingly, referred to in the dependently
docs/tutorial/modules.rst+14−12
@@ -10,11 +10,11 @@ module, a list of ``import`` statements giving the other modules which
1010are to be imported, and a collection of declarations and definitions of
1111types, classes and functions. For example, the listing below gives a
1212module which defines a binary tree type ``BTree`` (in a file
13−``btree.idr``):
13+``Btree.idr``):
1414
1515.. code-block:: idris
1616
17− module btree
17+ module Btree
1818
1919 data BTree a = Leaf
2020 | Node (BTree a) a (BTree a)
@@ -40,23 +40,24 @@ Then, this gives a main program (in a file
4040
4141 module Main
4242
43− import btree
43+ import Btree
4444
4545 main : IO ()
4646 main = do let t = toTree [1,8,2,7,9,3]
4747 print (btree.toList t)
4848
4949
50+
5051The same names can be defined in multiple modules. This is possible
5152because in practice names are *qualified* with the name of the module.
5253The names defined in the ``btree`` module are, in full:
5354
54−+ ``btree.BTree``
55−+ ``btree.Leaf``
56−+ ``btree.Node``
57−+ ``btree.insert``
58−+ ``btree.toList``
59−+ ``btree.toTree``
55++ ``Btree.BTree``
56++ ``Btree.Leaf``
57++ ``Btree.Node``
58++ ``Btree.insert``
59++ ``Btree.toList``
60++ ``Btree.toTree``
6061
6162If names are otherwise unambiguous, there is no need to give the fully
6263qualified name. Names can be disambiguated either by giving an explicit
@@ -103,7 +104,7 @@ functions to be exported as ``abstract``, as we see below:
103104
104105.. code-block:: idris
105106
106− module btree
107+ module Btree
107108
108109 abstract data BTree a = Leaf
109110 | Node (BTree a) a (BTree a)
@@ -137,7 +138,8 @@ the ``public`` modifier on an ``import``. For example:
137138
138139 module A
139140
140− import B import public C
141+ import B
142+ import public C
141143
142144 public a : AType a = ...
143145
@@ -154,7 +156,7 @@ wish to overload names within the same module:
154156
155157.. code-block:: idris
156158
157− module foo
159+ module Foo
158160
159161 namespace x
160162 test : Int -> Int
docs/tutorial/starting.rst+9−13
@@ -10,12 +10,9 @@ Prerequisites
1010Before installing Idris, you will need to make sure you have all
1111of the necessary libraries and tools. You will need:
1212
13−- A fairly recent Haskell platform. Version 2013.2.0.0 should be
14− sufficiently recent, though it is better to be completely up to
15− date.
13+- A fairly recent Haskell platform. Version ``2013.2.0.0`` should be sufficiently recent, though it is better to be completely up to date.
1614
17−- The *GNU Multiple Precision Arithmetic Library* (GMP) is available
18− from MacPorts/Homebrew and all major Linux distributions.
15+- The *GNU Multiple Precision Arithmetic Library* (GMP) is available from MacPorts/Homebrew and all major Linux distributions.
1916
2017Downloading and Installing
2118==========================
@@ -33,7 +30,7 @@ development version you can find it, as well as build intructions, on
3330GitHub at: https://github.com/idris-lang/Idris-dev.
3431
3532To check that installation has succeeded, and to write your first
36−Idris program, create a file called “``hello.idr``” containing the
33+Idris program, create a file called ``hello.idr`` containing the
3734following text:
3835
3936.. code-block:: idris
@@ -55,18 +52,17 @@ create an executable called ``hello``, which you can run:
5552 $ ./hello
5653 Hello world
5754
58−Note that the ``$`` indicates the shell prompt! Should the Idris
59−executable not be found please ensure that you have added
60−``~/.cabal/bin`` to your ``$PATH`` environment variable. Mac OS X
61−users may find they need to use ``~/Library/Haskell/bin``
55+Please note that the dollar sign ``$`` indicates the shell prompt!
56+Should the Idris executable not be found please ensure that you have
57+added ``~/.cabal/bin`` to your ``$PATH`` environment variable. Mac OS
58+X users may find they need to add ``~/Library/Haskell/bin``
6259instead. Some useful options to the Idris command are:
6360
6461- ``-o prog`` to compile to an executable called ``prog``.
6562
66−- ``--check`` type check the file and its dependencies without
67− starting the interactive environment.
63+- ``--check`` type check the file and its dependencies without starting the interactive environment.
6864
69−- ``--help`` display usage summary and command line options
65+- ``--help`` display usage summary and command line options.
7066
7167The Interactive Environment
7268===========================
docs/tutorial/typesfuns.rst+37−33
@@ -12,13 +12,13 @@ Idris defines several primitive types: ``Int``, ``Integer`` and
1212manipulation, 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
15−these types. Enter the following into a file ``prims.idr`` and load it
15+these types. Enter the following into a file ``Prims.idr`` and load it
1616into the Idris interactive environment by typing ``idris
17−prims.idr``:
17+Prims.idr``:
1818
1919.. code-block:: idris
2020
21− module prims
21+ module Prims
2222
2323 x : Int
2424 x = 42
@@ -33,17 +33,18 @@ prims.idr``:
3333 quux = False
3434
3535An Idris file consists of an optional module declaration (here
36−``module prims``) followed by an optional list of imports (none here,
37−however Idris programs can consist of several modules, and the
38−definitions in each module each have their own namespace, as we will
39−discuss in Section :ref:`sect-namespaces`) and a collection of
40−declarations and definitions. The order of definitions is significant
41−— functions and data types must be defined before use. Each definition
42−must have a type declaration, for example see ``x : Int``, ``foo :
43−String``, from the above listing. Indentation is significant — a new
44−declaration begins at the same level of indentation as the preceding
45−declaration. Alternatively, declarations may be terminated with a
46−semicolon.
36+``module Prims``) followed by an optional list of imports and a
37+collection of declarations and definitions. In this example no imports
38+have been specified. However Idris programs can consist of several
39+modules and the definitions in each module each have their own
40+namespace. This is discussed further in Section
41+:ref:`sect-namespaces`). When writing Idris programs both the order in
42+definitions are given and indentation are significant. Functions and
43+data types must be defined before use, incidently each definition must
44+have a type declaration, for example see ``x : Int``, ``foo :
45+String``, from the above listing. New declarations must begin at the
46+same level of indentation as the preceding declaration.
47+Alternatively, a semicolon ``;`` can be used to terminate declarations.
4748
4849A library module ``prelude`` is automatically imported by every
4950Idris program, including facilities for IO, arithmetic, data
@@ -63,7 +64,7 @@ All of the usual arithmetic and comparison operators are defined for
6364the primitive types. They are overloaded using type classes, as we
6465will discuss in Section :ref:`sect-classes` and can be extended to
6566work on user defined types. Boolean expressions can be tested with the
66−``if...then...else`` construct:
67+``if...then...else`` construct, for example:
6768
6869::
6970
@@ -73,9 +74,9 @@ work on user defined types. Boolean expressions can be tested with the
7374Data Types
7475==========
7576
76−Data types are declared in a similar way to Haskell data types, with a
77−similar syntax. Natural numbers and lists, for example, can be
78−declared as follows:
77+Data types are declared in a similar way and with similar syntax to
78+Haskell. Natural numbers and lists, for example, can be declared as
79+follows:
7980
8081.. code-block:: idris
8182
@@ -193,11 +194,13 @@ does not need to be visible globally:
193194Indentation is significant — functions in the ``where`` block must be
194195indented further than the outer function.
195196
196−**Scope:** Any names which are visible in the outer scope are also
197−visible in the ``where`` clause (unless they have been redefined, such
198−as ``xs`` here). A name which appears only in the type will be in scope
199−in the ``where`` clause if it is a *parameter* to one of the types,
200−i.e. it is fixed across the entire structure.
197+.. note:: Scope
198+
199+ Any names which are visible in the outer scope are also visible in
200+ the ``where`` clause (unless they have been redefined, such as ``xs``
201+ here). A name which appears only in the type will be in scope in the
202+ ``where`` clause if it is a *parameter* to one of the types, i.e. it
203+ is fixed across the entire structure.
201204
202205As well as functions, ``where`` blocks can include local data
203206declarations, such as the following where ``MyLT`` is not accessible
@@ -306,16 +309,17 @@ following:
306309 $ idris vbroken.idr --check
307310 vbroken.idr:9:23:When elaborating right hand side of Vect.++:
308311 When elaborating an application of constructor Vect.:::
309− Can't unify
310− Vect (k + k) a
311− with
312− Vect (plus k m) a
313−
314− Specifically:
315− Can't unify
316− plus k k
317− with
318− plus k m
312+ Can't unify
313+ Vect (k + k) a (Type of xs ++ xs)
314+ with
315+ Vect (plus k m) a (Expected type)
316+
317+ Specifically:
318+ Can't unify
319+ plus k k
320+ with
321+ plus k m
322+
319323
320324This error message suggests that there is a length mismatch between
321325two vectors — we needed a vector of length ``k + m``, but provided a
docs/tutorial/views.rst+2−2
@@ -83,8 +83,8 @@ rule:
8383The value of the result of ``parity k`` affects the form of ``k``,
8484because the result of ``parity k`` depends on ``k``. So, as well as
8585the patterns for the result of the intermediate computation (``Even``
86−and ``odd``) right of the ``\mid``, we also write how the results
87−affect the other patterns left of the :math:`\mid`. Note that there is
86+and ``odd``) right of the ``|``, we also write how the results
87+affect the other patterns left of the ``|``. Note that there is
8888a function in the patterns (``+``) and repeated occurrences of
8989``j``—this is allowed because another argument has determined the form
9090of these patterns.