on master help sign in
Merge pull request #2394 from jfdm/doc/updates

Documentation Updates

commit1aa9f0b3dd63a04af5e0dcbb3c3d84fd801b51ee authorJan de Muijnck-Hughes <jfdm@users.noreply.github.com> dateSun 5 Jul 2015, 14:38 (11 years ago) parent64365db434dbab
7 files changed+214−49
docs/index.rst+4 docs/reference/elaborator-reflection.rst+6 docs/reference/index.rst+4−4 docs/reference/packages.rst+101 docs/tutorial/index.rst+1 docs/tutorial/packages.rst+33−45 docs/tutorial/testing.rst+65
docs/index.rst+4
@@ -39,6 +39,7 @@ The Idris Tutorial
3939 tutorial/classes
4040 tutorial/modules
4141 tutorial/packages
42+ tutorial/testing
4243 tutorial/interp
4344 tutorial/views
4445 tutorial/theorems
@@ -101,8 +102,10 @@ Language Reference
101102 :maxdepth: 1
102103
103104 reference/documenting
105+ reference/packages
104106 reference/uniqueness-types
105107 reference/ffi
108+ reference/syntax-guide
106109 reference/erasure
107110 reference/ide-protocol
108111 reference/semantic-highlighting
@@ -111,6 +114,7 @@ Language Reference
111114 reference/compilation
112115 reference/language-features
113116 reference/language-extensions
117+ reference/elaborator-reflection
114118 reference/misc
115119
116120.. _guides:
docs/reference/elaborator-reflection.rst+6
@@ -38,11 +38,13 @@ The meta-operation ``%runElab script`` runs ``script`` in the current elaboratio
3838For example, the following script constructs the identity function at type ``Nat``:
3939
4040.. code-block:: idris
41+
4142 idNat : Nat -> Nat
4243 idNat = %runElab (do intro (Just (UN "x"))
4344 fill (Var (UN "x"))
4445 solve)
4546
47+
4648On the right-hand side, the Idris elaborator has the goal ``Nat -> Nat``.
4749When it encounters the ``%runElab`` directive, it fulfills this goal by running the provided script.
4850The first tactic, ``intro``, constructs a lambda that binds the name ``x``.
@@ -56,6 +58,7 @@ Note that there is nothing ``Nat``-specific about the above script.
5658We can generate identity functions at any concrete type using the same script:
5759
5860.. code-block:: idris
61+
5962 mkId : Elab ()
6063 mkId = do intro (Just (UN "x"))
6164 fill (Var (UN "x"))
@@ -70,6 +73,7 @@ We can generate identity functions at any concrete type using the same script:
7073 idString : String -> String
7174 idString = %runElab mkId
7275
76+
7377Interactively Building Elab Scripts
7478===================================
7579
@@ -99,6 +103,7 @@ The ordinary Idris bind syntax can be used to propagate this information.
99103For example, a tactic that solves the current goal when it is the unit type might look like this:
100104
101105.. code-block:: idris
106+
102107 triv : Elab ()
103108 triv = do compute
104109 g <- getGoal
@@ -109,6 +114,7 @@ For example, a tactic that solves the current goal when it is the unit type migh
109114 , TextPart "is not trivial"
110115 ]
111116
117+
112118The tactic ``compute`` normalises the type of its goal with respect to the current context.
113119While not strictly necessary, this allows ``triv`` to be used in contexts where the triviality of the goal is not immediately apparent.
114120Then, ``getGoal`` is used, and its result is bound to ``g``.
docs/reference/index.rst+4−4
@@ -21,17 +21,17 @@ This will tell you how Idris works, for using it you should read the Idris Tutor
2121 :maxdepth: 1
2222
2323 documenting
24+ packages
2425 uniqueness-types
2526 ffi
27+ syntax-guide
2628 erasure
29+ ide-protocol
2730 semantic-highlighting
28− repl
29− syntax-guide
3031 tactics
32+ repl
3133 compilation
3234 language-features
3335 language-extensions
3436 elaborator-reflection
3537 misc
36−
37−
docs/reference/packages.rstnew file+101
@@ -0,0 +1,101 @@
1+.. _ref-sect-packages:
2+
3+********
4+Packages
5+********
6+
7+Idris includes a simple system for building packages from a
8+package description file. These files can be used with the Idris
9+compiler to manage the development process of your Idris
10+programmes and packages.
11+
12+Package Descriptions
13+====================
14+
15+A package description includes the following:
16+
17++ A header, consisting of the keyword package followed by the package name.
18++ Fields describing package contents, ``<field> = <value>``
19+
20+At least one field must be the modules field, where the value is a
21+comma separated list of modules. For example, a library test which
22+has two modules ``foo.idr`` and ``bar.idr`` as source files would be
23+written as follows::
24+
25+ package foo
26+
27+ modules = foo, bar
28+
29+Other examples of package files can be found in the ``libs`` directory
30+of the main Idris repository, and in `third-party libraries <https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
31+
32+Common Fields
33+-------------
34+
35+Other common fields which may be present in an ``ipkg`` file are:
36+
37++ ``sourcedir = <dir>``, which takes the directory (relative to the
38+ current directory) which contains the source. Default is the current
39+ directory.
40+
41++ ``executable = <output>``, which takes the name of the executable
42+ file to generate.
43+
44++ ``main = <module>``, which takes the name of the main module, and
45+ must be present if the executable field is present.
46+
47++ ``opts = "<idris options>"``, which allows options (such as other
48+ packages) to be passed to Idris.
49+
50+Binding to C
51+------------
52+
53+In more advanced cases, particularly to support creating bindings to
54+external ``C`` libraries, the following options are available:
55+
56++ ``makefile = <file>``, which specifies a ``Makefile``, to be built
57+ before the Idris modules, for example to support linking with a
58+ ``C`` library.
59+
60++ ``libs = <libs>``, which takes a comma separated list of libraries
61+ which must be present for the package to be usable.
62+
63++ ``objs = <objs>``, which takes a comma separated list of additional
64+ object files to be installed, perhaps generated by the ``Makefile``.
65+
66+Testing
67+--------
68+
69+For testing Idris packages there is a rudimentary testing harness, run in the ``IO`` context.
70+The ``iPKG`` file is used to specify the functions used for testing.
71+The following option is available:
72+
73++ ``tests = <test functions>``, which takes the qualified names of all test functions to be run.
74+
75+.. IMPORTANT::
76+ The modules containing the test functions must also be added to the list of modules.
77+
78+Using Package files
79+===================
80+
81+Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
82+
83++ ``idris --build test.ipkg`` will build all modules in the package
84+
85++ ``idris --install test.ipkg`` will install the package, making it
86+ accessible by other Idris libraries and programs.
87+
88++ ``idris --clean test.ipkg`` will delete all intermediate code and
89+ executable files generated when building.
90+
91++ ``idris --mkdoc test.ipkg`` will build HTML documentation for your package in the folder ``test_doc`` in your project's root directory.
92+
93++ ``idris --checkpkg test.ipkg`` will type check all modules in the package only. This differs from build that type checks **and** generates code.
94+
95++ ``idris --testpkg test.ipkg`` will compile and run any embedded tests you have specified in the ``tests`` paramater.
96+
97+Once the test package has been installed, the command line option
98+``--package test`` makes it accessible (abbreviated to ``-p test``).
99+For example::
100+
101+ idris -p test Main.idr
docs/tutorial/index.rst+1
@@ -24,6 +24,7 @@ The is the Idris Tutorial. It will teach you about programming in the Idris Lang
2424 classes
2525 modules
2626 packages
27+ testing
2728 interp
2829 views
2930 theorems
docs/tutorial/packages.rst+33−45
@@ -1,13 +1,10 @@
1−.. _sect-packages:
2−
31********
42Packages
53********
64
7−Idris includes a simple system for building packages from a
8−package description file. These files can be used with the Idris
9−compiler to manage the development process of your Idris
10−programmes and packages.
5+
6+Idris includes a simple build system for building packages and executables from a named package description file.
7+These files can be used with the Idris compiler to manage the development process .
118
129Package Descriptions
1310====================
@@ -18,60 +15,51 @@ A package description includes the following:
1815+ Fields describing package contents, ``<field> = <value>``
1916
2017At least one field must be the modules field, where the value is a
21−comma separated list of modules. For example, a library test which
22−has two modules ``foo.idr`` and ``bar.idr`` as source files would be
23−written as follows::
18+comma separated list of modules. For example, given an idris package
19+``maths`` that has modules ``Maths.idr``, ``Maths.NumOps.idr``,
20+``Maths.BinOps.idr``, and ``Maths.HexOps.idr``, the corresponding
21+package file would be::
2422
25− package foo
23+ package maths
24+
25+ modules = Maths
26+ , Maths.NumOps
27+ , Maths.BinOps
28+ , Maths.HexOps
2629
27− modules = foo, bar
2830
2931Other examples of package files can be found in the ``libs`` directory
3032of the main Idris repository, and in `third-party libraries <https://github.com/idris-lang/Idris-dev/wiki/Libraries>`_.
33+More details including a complete listing of available fields can be found in :ref:`ref-sect-packages`.
3134
32−Other common fields which may be present in an ``ipkg`` file are:
33−
34−+ ``sourcedir = <dir>``, which gives the directory (relative to the
35− current directory) which contains the source. Default is the current
36− directory.
37−
38−+ ``executable = <output>``, which gives the name of the executable
39− file to generate.
40−
41−+ ``main = <module>``, which gives the name of the main module, and
42− must be present if the executable field is present.
43−
44−+ ``opts = "<idris options>"``, which allows options (such as other
45− packages) to be passed to Idris.
46−
47−In more advanced cases, particularly to support creating bindings to
48−external ``C`` libraries, the following options are available:
49−
50−+ ``makefile = <file>``, which specifies a ``Makefile``, to be built
51− before the Idris modules, for example to support linking with a
52− ``C`` library.
53−
54−+ ``libs = <libs>``, which gives a comma separated list of libraries
55− which must be present for the package to be usable.
56−
57−+ ``objs = <objs>``, which gives a comma separated list of additional
58− object files to be installed, perhaps generated by the ``Makefile``.
5935
6036Using Package files
6137===================
6238
63−Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
39+Given an Idris package file ``maths.ipkg`` it can be used with the Idris compiler as follows:
6440
65−+ ``idris --build test.ipkg`` will build all modules in the package
41++ ``idris --build maths.ipkg`` will build all modules in the package
6642
67−+ ``idris --install test.ipkg`` will install the package, making it
43++ ``idris --install maths.ipkg`` will install the package, making it
6844 accessible by other Idris libraries and programs.
6945
70−+ ``idris --clean test.ipkg`` will delete all intermediate code and
46++ ``idris --clean maths.ipkg`` will delete all intermediate code and
7147 executable files generated when building.
7248
73−Once the test package has been installed, the command line option
74−``--package test`` makes it accessible (abbreviated to ``-p test``).
49++ ``idris --mkdoc maths.ipkg`` will build HTML documentation for your
50+ package in the folder ``maths_doc`` in your project's root
51+ directory.
52+
53++ ``idris --checkpkg maths.ipkg`` will type check all modules in the
54+ package only. This differs from build that type checks **and**
55+ generates code.
56+
57++ ``idris --mathspkg maths.ipkg`` will compile and run any embedded
58+ mathss you have specified in the ``tests`` paramater. More
59+ information about mathsing is given in the next section.
60+
61+Once the maths package has been installed, the command line option
62+``--package maths`` makes it accessible (abbreviated to ``-p maths``).
7563For example::
7664
77− idris -p test Main.idr
65+ idris -p maths Main.idr
docs/tutorial/testing.rstnew file+65
@@ -0,0 +1,65 @@
1+.. _tut-sect-testing:
2+
3+**********************
4+Testing Idris Packages
5+**********************
6+
7+As part of the integrated build system a simple testing framework is provided.
8+This framework will collect a list of named functions and construct an Idris executable in a fresh environment on your machine.
9+This executable lists the named functions under a single ``main`` function, and imports the complete list of modules for the package.
10+
11+
12+It is up to the developer to ensure the correct reporting of test results, and the structure and nature of how the tests are run.
13+Further, all test functions must return ``IO ()``, and must be listed in the ``ipkg`` file under ``tests``, and rhe modules containing the test functions must also be listed in the modules section of the ``iPKG`` file.
14+
15+
16+For example, lets take the following list of functions that are defined in a module called ``NumOps`` for a sample package ``maths``.
17+
18+.. code-block:: idris
19+
20+ module Maths.NumOps
21+
22+ double : Num a => a -> a
23+ double a = a + a
24+
25+ triple : Num a => a -> a
26+ triple a = a + double a
27+
28+A simple test module, with a qualified name of ``Test.NumOps`` can be declared as
29+
30+.. code-block:: idris
31+
32+ module Test.NumOps
33+
34+ import Maths.NumOps
35+
36+ assertEq : Eq a => (given : a) -> (expected : a) -> IO ()
37+ assertEq g e = if g == e
38+ then putStrLn "Test Passed"
39+ else putStrLn "Test failed"
40+
41+ assertNotEq : Eq a => (given : a) -> (expected : a) -> IO ()
42+ assertNotEq g e = if not (g == e)
43+ then putStrLn "Test Passed"
44+ else putStrLn "Test failed"
45+
46+ testDouble : IO ()
47+ testDouble = assertEq (double 2) 4
48+
49+ testTriple : IO ()
50+ testTriple = assertNotEq (triple 2) 5
51+
52+
53+The functions ``assertEq`` and ``assertNotEq`` are used to run expected passing, and failing, equality tests.
54+The actual tests are ``testDouble`` and ``testTriple``, and are declared in the ``maths.ipkg`` file as follows::
55+
56+ module maths
57+
58+ module = Maths.NumOps
59+ , Test.NumOps
60+
61+ tests = Test.NumOps.testDouble
62+ , Test.NumOps.testTriple
63+
64+
65+The testing framework can be invoked using: ``idris --testpkg maths.ipkg``.