on master help sign in
Merge pull request #2082 from jfdm/docs/heading-fixes
9429eb6Jan de Muijnck-Hughes
docs/effects/conclusions.rst+2−2
@@ -1,8 +1,8 @@
1.. _sect-further:
1.. _sect-further:
2
2
3−===============
3+***************
4Further Reading
4Further Reading
5−===============
5+***************
6
6
7This tutorial has given an introduction to writing and reasoning about
7This tutorial has given an introduction to writing and reasoning about
8side-effecting programs in Idris, using the ``Effects`` library.
8side-effecting programs in Idris, using the ``Effects`` library.
docs/effects/depeff.rst+6−6
@@ -1,8 +1,8 @@
1.. _sect-depeff:
1.. _sect-depeff:
2
2
3−=================
3+*****************
4Dependent Effects
4Dependent Effects
5−=================
5+*****************
6
6
7In the programs we have seen so far, the available effects have remained
7In the programs we have seen so far, the available effects have remained
8constant. Sometimes, however, an operation can *change* the available
8constant. Sometimes, however, an operation can *change* the available
@@ -16,7 +16,7 @@ we will see how this can be used to implement a type-safe and
16resource-safe protocol for file management.
16resource-safe protocol for file management.
17
17
18Dependent States
18Dependent States
19−----------------
19+================
20
20
21Suppose we have a function which reads input from the console, converts
21Suppose we have a function which reads input from the console, converts
22it to an integer, and adds it to a list which is stored in a ``STATE``.
22it to an integer, and adds it to a list which is stored in a ``STATE``.
@@ -59,7 +59,7 @@ It has the following type:
59 putM : y -> { [STATE x] ==> [STATE y] } Eff ()
59 putM : y -> { [STATE x] ==> [STATE y] } Eff ()
60
60
61Result-dependent Effects
61Result-dependent Effects
62−------------------------
62+========================
63
63
64Often, whether a state is updated could depend on the success or
64Often, whether a state is updated could depend on the success or
65otherwise of an operation. In our ``readInt`` example, we might wish to
65otherwise of an operation. In our ``readInt`` example, we might wish to
@@ -134,7 +134,7 @@ check (i.e. whether reading a value succeeded) has indeed been done.
134 being inspected in the type of each branch.
134 being inspected in the type of each branch.
135
135
136File Management
136File Management
137−---------------
137+===============
138
138
139A practical use for dependent effects is in specifying resource usage
139A practical use for dependent effects is in specifying resource usage
140protocols and verifying that they are executed correctly. For example,
140protocols and verifying that they are executed correctly. For example,
@@ -242,7 +242,7 @@ reading, but the effect list contains a ``FILE_IO`` effect carrying a
242file open for writing.
242file open for writing.
243
243
244Pattern-matching bind
244Pattern-matching bind
245−---------------------
245+=====================
246
246
247It might seem that having to test each potentially failing operation
247It might seem that having to test each potentially failing operation
248with a ``case`` clause could lead to ugly code, with lots of
248with a ``case`` clause could lead to ugly code, with lots of
docs/effects/hangman.rst+10−10
@@ -1,8 +1,8 @@
1.. _sect-hangman:
1.. _sect-hangman:
2
2
3−=======================================
3+***************************************
4Example: A “Mystery Word” Guessing Game
4Example: A “Mystery Word” Guessing Game
5−=======================================
5+***************************************
6
6
7In this section, we will use the techniques and specific effects
7In this section, we will use the techniques and specific effects
8discussed in the tutorial so far to implement a larger example, a simple
8discussed in the tutorial so far to implement a larger example, a simple
@@ -29,7 +29,7 @@ using the newly defined effect (and any others required to implement the
29interface).
29interface).
30
30
31Step 1: Game State
31Step 1: Game State
32−------------------
32+==================
33
33
34First, we categorise the game states as running games (where there are a
34First, we categorise the game states as running games (where there are a
35number of guesses available, and a number of letters still to guess), or
35number of guesses available, and a number of letters still to guess), or
@@ -53,7 +53,7 @@ this data:
53 data Mystery : GState -> Type
53 data Mystery : GState -> Type
54
54
55Step 2: Game Rules
55Step 2: Game Rules
56−------------------
56+==================
57
57
58We describe the game rules as a dependent effect, where each action has
58We describe the game rules as a dependent effect, where each action has
59a *precondition* (i.e. what the game state must be before carrying out
59a *precondition* (i.e. what the game state must be before carrying out
@@ -131,7 +131,7 @@ then allow us to play the game.
131 MYSTERY h = MkEff (Mystery h) MysteryRules
131 MYSTERY h = MkEff (Mystery h) MysteryRules
132
132
133Step 3: Implement Rules
133Step 3: Implement Rules
134−-----------------------
134+=======================
135
135
136To *implement* the rules, we begin by giving a concrete definition of
136To *implement* the rules, we begin by giving a concrete definition of
137game state:
137game state:
@@ -211,7 +211,7 @@ such a way that the number of missing letters or number of guesses does
211not follow the rules.
211not follow the rules.
212
212
213Step 4: Implement Interface
213Step 4: Implement Interface
214−---------------------------
214+===========================
215
215
216Having described the rules, and implemented state transitions which
216Having described the rules, and implemented state transitions which
217follow those rules as an effect handler, we can now write an interface
217follow those rules as an effect handler, we can now write an interface
@@ -225,7 +225,7 @@ for the game which uses the ``MYSTERY`` effect:
225The type indicates that the game must start in a running state, with
225The type indicates that the game must start in a running state, with
226some guesses available, and eventually reach a not-running state (i.e.
226some guesses available, and eventually reach a not-running state (i.e.
227won or lost). The only way to achieve this is by correctly following the
227won or lost). The only way to achieve this is by correctly following the
228−stated rules.
228+stated rules.
229
229
230Note that the type of ``game`` makes no assumption that there are
230Note that the type of ``game`` makes no assumption that there are
231letters to be guessed in the given word (i.e. it is ``w`` rather than
231letters to be guessed in the given word (i.e. it is ``w`` rather than
@@ -267,7 +267,7 @@ generator, then pick a random ``Fin`` to index into a list of
267 limited form of type inference, but very useful in practice.
267 limited form of type inference, but very useful in practice.
268
268
269A possible complete implementation of ``game`` is
269A possible complete implementation of ``game`` is
270−presented below:
270+presented below:
271
271
272.. code-block:: idris
272.. code-block:: idris
273
273
@@ -298,7 +298,7 @@ presented below:
298 (S k) => game
298 (S k) => game
299
299
300Discussion
300Discussion
301−----------
301+==========
302
302
303Writing the rules separately as an effect, then an implementation
303Writing the rules separately as an effect, then an implementation
304which uses that effect, ensures that the implementation must follow
304which uses that effect, ensures that the implementation must follow
@@ -330,4 +330,4 @@ These are, of course, simple errors, but were caught by the type
330checker before any testing of the game.
330checker before any testing of the game.
331
331
332.. [1]
332.. [1]
333− Readers may recognise this game by the name “Hangman.”
333+ Readers may recognise this game by the name “Hangman”.
docs/effects/impleff.rst+9−10
@@ -1,8 +1,8 @@
1.. _sect-impleff:
1.. _sect-impleff:
2
2
3−====================
3+********************
4Creating New Effects
4Creating New Effects
5−====================
5+********************
6
6
7We have now seen several side-effecting operations provided by the
7We have now seen several side-effecting operations provided by the
8``Effects`` library, and examples of their use in Section
8``Effects`` library, and examples of their use in Section
@@ -14,7 +14,7 @@ selection of the available effects are implemented, and show how new
14effectful operations may be provided.
14effectful operations may be provided.
15
15
16State
16State
17−-----
17+=====
18
18
19Effects are described by *algebraic data types*, where the
19Effects are described by *algebraic data types*, where the
20constructors describe the operations provided when the effect is
20constructors describe the operations provided when the effect is
@@ -154,7 +154,7 @@ Such details are not important for using the library, or even writing
154new effects, however.
154new effects, however.
155
155
156Summary
156Summary
157−~~~~~~~
157+-------
158
158
159The following listing summarises what is required to define the
159The following listing summarises what is required to define the
160``STATE`` effect:
160``STATE`` effect:
@@ -183,7 +183,7 @@ The following listing summarises what is required to define the
183
183
184
184
185Console I/O
185Console I/O
186−-----------
186+===========
187
187
188Then listing below gives the definition of the ``STDIO``
188Then listing below gives the definition of the ``STDIO``
189effect, including handlers for ``IO`` and ``IOExcept``. We omit the
189effect, including handlers for ``IO`` and ``IOExcept``. We omit the
@@ -219,7 +219,7 @@ directly.
219 STDIO = MkEff () StdIO
219 STDIO = MkEff () StdIO
220
220
221Exceptions
221Exceptions
222−----------
222+==========
223
223
224The listing below gives the definition of the ``Exception``
224The listing below gives the definition of the ``Exception``
225effect, including two of its handlers for ``Maybe`` and ``List``. The
225effect, including two of its handlers for ``Maybe`` and ``List``. The
@@ -244,7 +244,7 @@ error.
244
244
245
245
246Non-determinism
246Non-determinism
247−---------------
247+===============
248
248
249The following listing gives the definition of the ``Select``
249The following listing gives the definition of the ``Select``
250effect for writing non-deterministic programs, including a handler for
250effect for writing non-deterministic programs, including a handler for
@@ -277,10 +277,10 @@ accumulate all successful results, and in the ``Maybe`` handler we try
277the first value in the last, and try later values only if that fails.
277the first value in the last, and try later values only if that fails.
278
278
279File Management
279File Management
280−---------------
280+===============
281
281
282Result-dependent effects are no different from non-dependent effects
282Result-dependent effects are no different from non-dependent effects
283−in the way they are implemented. The listing below
283+in the way they are implemented. The listing below
284illustrates this for the ``FILE_IO`` effect. The syntax for state
284illustrates this for the ``FILE_IO`` effect. The syntax for state
285transitions ``{ x ==> {res} x’ }``, where the result state ``x’`` is
285transitions ``{ x ==> {res} x’ }``, where the result state ``x’`` is
286computed from the result of the operation ``res``, follows that for
286computed from the result of the operation ``res``, follows that for
@@ -320,4 +320,3 @@ continuation ``k`` are different depending on whether the result is
320``True`` (opening succeeded) or ``False`` (opening failed). This uses
320``True`` (opening succeeded) or ``False`` (opening failed). This uses
321``validFile``, defined in the ``Prelude``, to test whether a file
321``validFile``, defined in the ``Prelude``, to test whether a file
322handler refers to an open file or not.
322handler refers to an open file or not.
323−
docs/effects/introduction.rst+2−2
@@ -1,6 +1,6 @@
1−============
1+************
2Introduction
2Introduction
3−============
3+************
4
4
5Pure functional languages with dependent types such as `Idris
5Pure functional languages with dependent types such as `Idris
6<http://idris-lang.org/>`_ support reasoning about programs directly
6<http://idris-lang.org/>`_ support reasoning about programs directly
docs/effects/simpleeff.rst+13−13
@@ -1,8 +1,8 @@
1.. _sect-simpleff:
1.. _sect-simpleff:
2
2
3−==============
3+**************
4Simple Effects
4Simple Effects
5−==============
5+**************
6
6
7So far we have seen how to write programs with locally mutable state
7So far we have seen how to write programs with locally mutable state
8using the ``STATE`` effect. To recap, we have the definitions below
8using the ``STATE`` effect. To recap, we have the definitions below
@@ -41,7 +41,7 @@ All of the effects in the library, including those described in this
41section, are summarised in Appendix :ref:`sect-appendix`.
41section, are summarised in Appendix :ref:`sect-appendix`.
42
42
43Console I/O
43Console I/O
44−-----------
44+===========
45
45
46Console I/O is supported with the ``STDIO``
46Console I/O is supported with the ``STDIO``
47effect, which allows reading and writing characters and strings to and
47effect, which allows reading and writing characters and strings to and
@@ -67,7 +67,7 @@ can perform (or at the very least simulate) console I/O:
67 instance Handler StdIO (IOExcept a)
67 instance Handler StdIO (IOExcept a)
68
68
69Examples
69Examples
70−~~~~~~~~
70+--------
71
71
72A program which reads the user’s name, then says hello, can be written
72A program which reads the user’s name, then says hello, can be written
73as follows:
73as follows:
@@ -117,7 +117,7 @@ read and write from the console. To run this, ``main`` does not need
117to be changed.
117to be changed.
118
118
119Aside: Resource Types
119Aside: Resource Types
120−~~~~~~~~~~~~~~~~~~~~~
120+---------------------
121
121
122To find out the resource type of an effect, if necessary (for example
122To find out the resource type of an effect, if necessary (for example
123if we want to initialise a resource explicitiy with ``runInit`` rather
123if we want to initialise a resource explicitiy with ``runInit`` rather
@@ -132,7 +132,7 @@ than using a default value with ``run``) we can run the
132 Int : Type
132 Int : Type
133
133
134Exceptions
134Exceptions
135−----------
135+==========
136
136
137The ``EXCEPTION``
137The ``EXCEPTION``
138effect is declared in module ``Effect.Exception``. This allows programs
138effect is declared in module ``Effect.Exception``. This allows programs
@@ -155,7 +155,7 @@ generally:
155 instance Show a => Handler (Exception a) IO
155 instance Show a => Handler (Exception a) IO
156
156
157Example
157Example
158−~~~~~~~
158+-------
159
159
160Suppose we have a ``String`` which is expected to represent an integer
160Suppose we have a ``String`` which is expected to represent an integer
161in the range ``0`` to ``n``. We can write a function ``parseNumber``
161in the range ``0`` to ``n``. We can write a function ``parseNumber``
@@ -232,7 +232,7 @@ the boundedness proof:
232 else raise NotANumber
232 else raise NotANumber
233
233
234Random Numbers
234Random Numbers
235−--------------
235+==============
236
236
237Random number generation is also implemented by the library, in module
237Random number generation is also implemented by the library, in module
238``Effect.Random``:
238``Effect.Random``:
@@ -263,7 +263,7 @@ produce a random number:
263 (essentially a number with an upper bound given in its type).
263 (essentially a number with an upper bound given in its type).
264
264
265Example
265Example
266−~~~~~~~
266+-------
267
267
268We can use the ``RND`` effect to implement a simple guessing game. The
268We can use the ``RND`` effect to implement a simple guessing game. The
269``guess`` function, given a target number, will repeatedly ask the
269``guess`` function, given a target number, will repeatedly ask the
@@ -317,7 +317,7 @@ do this, see the ``SYSTEM`` effect described in :ref:`sect-appendix`.
317
317
318
318
319Non-determinism
319Non-determinism
320−---------------
320+===============
321
321
322The listing below gives the definition of the non-determinism
322The listing below gives the definition of the non-determinism
323effect, which allows a program to choose a value non-deterministically
323effect, which allows a program to choose a value non-deterministically
@@ -337,7 +337,7 @@ succeeds:
337 instance Handler Selection List
337 instance Handler Selection List
338
338
339Example
339Example
340−~~~~~~~
340+-------
341
341
342The ``SELECT`` effect can be used to solve constraint problems, such
342The ``SELECT`` effect can be used to solve constraint problems, such
343as finding Pythagorean triples. The idea is to use ``select`` to give
343as finding Pythagorean triples. The idea is to use ``select`` to give
@@ -373,7 +373,7 @@ context). We can try this as follows:
373 print $ the (List _) $ run (triple 100)
373 print $ the (List _) $ run (triple 100)
374
374
375``vadd`` revisited
375``vadd`` revisited
376−------------------
376+==================
377
377
378We now return to the ``vadd`` program from the introduction. Recall the
378We now return to the ``vadd`` program from the introduction. Recall the
379definition:
379definition:
@@ -453,7 +453,7 @@ with gracefully.
453 else raise "Not a number"
453 else raise "Not a number"
454
454
455Example: An Expression Calculator
455Example: An Expression Calculator
456−---------------------------------
456+=================================
457
457
458To show how these effects can fit together, let us consider an
458To show how these effects can fit together, let us consider an
459evaluator for a simple expression language, with addition and integer
459evaluator for a simple expression language, with addition and integer
docs/effects/state.rst+8−8
@@ -1,8 +1,8 @@
1.. _sect-state:
1.. _sect-state:
2
2
3−=====
3+*****
4State
4State
5−=====
5+*****
6
6
7Many programs, even pure programs, can benefit from locally mutable
7Many programs, even pure programs, can benefit from locally mutable
8state. For example, consider a program which tags binary tree nodes
8state. For example, consider a program which tags binary tree nodes
@@ -34,7 +34,7 @@ specific value ``i``, has the following type:
34 treeTag : (i : Int) -> BTree a -> BTree (Int, a)
34 treeTag : (i : Int) -> BTree a -> BTree (Int, a)
35
35
36First attempt
36First attempt
37−-------------
37+=============
38
38
39Naïvely, we can implement ``treeTag`` by implementing a helper
39Naïvely, we can implement ``treeTag`` by implementing a helper
40function which propagates a counter, returning the result of the count
40function which propagates a counter, returning the result of the count
@@ -75,7 +75,7 @@ is local mutable state (the counter) which we have had to make
75explicit.
75explicit.
76
76
77Introducing ``Effects``
77Introducing ``Effects``
78−-----------------------
78+=======================
79
79
80Idris provides a library, ``Effects`` [3]_, which captures this
80Idris provides a library, ``Effects`` [3]_, which captures this
81pattern and many others involving effectful computation [1]_. An
81pattern and many others involving effectful computation [1]_. An
@@ -217,7 +217,7 @@ shown in Listing [introprog].
217 main = print (treeTag 1 testTree)
217 main = print (treeTag 1 testTree)
218
218
219Effects and Resources
219Effects and Resources
220−---------------------
220+=====================
221
221
222Each effect is associated with a *resource*, which is initialised
222Each effect is associated with a *resource*, which is initialised
223before an effectful program can be run. For example, in the case of
223before an effectful program can be run. For example, in the case of
@@ -261,7 +261,7 @@ implemented ``treeTag`` by initialising the state as follows:
261 treeTag i x = runPureInit [i] (treeTagAux x)
261 treeTag i x = runPureInit [i] (treeTagAux x)
262
262
263Labelled Effects
263Labelled Effects
264−----------------
264+================
265
265
266What if we have more than one state, especially more than one state of
266What if we have more than one state, especially more than one state of
267the same type? How would ``get`` and ``put`` know which state they
267the same type? How would ``get`` and ``put`` know which state they
@@ -358,7 +358,7 @@ effect. Note that labels are polymorphic in the label type ``lbl``.
358Hence, a label can be anything—a string, an integer, a type, etc.
358Hence, a label can be anything—a string, an integer, a type, etc.
359
359
360``!``-notation
360``!``-notation
361−--------------
361+==============
362
362
363In many cases, using ``do``-notation can make programs unnecessarily
363In many cases, using ``do``-notation can make programs unnecessarily
364verbose, particularly in cases where the value bound is used once,
364verbose, particularly in cases where the value bound is used once,
@@ -412,7 +412,7 @@ is lifted to:
412 f g'
412 f g'
413
413
414Syntactic Sugar and ``Eff``
414Syntactic Sugar and ``Eff``
415−---------------------------
415+===========================
416
416
417By now, you may be wondering about the syntax we are using for
417By now, you may be wondering about the syntax we are using for
418``Eff``, because it doesn’t look like a normal type! (If not, you may
418``Eff``, because it doesn’t look like a normal type! (If not, you may
docs/effects/summary.rst+9−9
@@ -1,14 +1,14 @@
1.. _sect-appendix:
1.. _sect-appendix:
2
2
3−===============
3+***************
4Effects Summary
4Effects Summary
5−===============
5+***************
6
6
7This appendix gives interfaces for the core effects provided by the
7This appendix gives interfaces for the core effects provided by the
8library.
8library.
9
9
10EXCEPTION
10EXCEPTION
11−---------
11+=========
12
12
13.. code-block:: idris
13.. code-block:: idris
14
14
@@ -29,7 +29,7 @@ EXCEPTION
29 instance Show a => Handler (Exception a) IO
29 instance Show a => Handler (Exception a) IO
30
30
31FILE\_IO
31FILE\_IO
32−--------
32+========
33
33
34.. code-block:: idris
34.. code-block:: idris
35
35
@@ -58,7 +58,7 @@ FILE\_IO
58 instance Handler FileIO IO
58 instance Handler FileIO IO
59
59
60RND
60RND
61−---
61+===
62
62
63.. code-block:: idris
63.. code-block:: idris
64
64
@@ -77,7 +77,7 @@ RND
77 instance Handler Random m
77 instance Handler Random m
78
78
79SELECT
79SELECT
80−------
80+======
81
81
82.. code-block:: idris
82.. code-block:: idris
83
83
@@ -93,7 +93,7 @@ SELECT
93 instance Handler Selection List
93 instance Handler Selection List
94
94
95STATE
95STATE
96−-----
96+=====
97
97
98.. code-block:: idris
98.. code-block:: idris
99
99
@@ -111,7 +111,7 @@ STATE
111 instance Handler State m
111 instance Handler State m
112
112
113STDIO
113STDIO
114−-----
114+=====
115
115
116.. code-block:: idris
116.. code-block:: idris
117
117
@@ -133,7 +133,7 @@ STDIO
133 instance Handler StdIO (IOExcept a)
133 instance Handler StdIO (IOExcept a)
134
134
135SYSTEM
135SYSTEM
136−------
136+======
137
137
138.. code-block:: idris
138.. code-block:: idris
139
139
docs/faq/faq.rst+12−12
@@ -1,9 +1,9 @@
1−==========================
1+**************************
2Frequently Asked Questions
2Frequently Asked Questions
3−==========================
3+**************************
4
4
5What are the differences between Agda and Idris?
5What are the differences between Agda and Idris?
6−------------------------------------------------
6+================================================
7
7
8The main difference is that Idris has been designed from the start to support
8The main difference is that Idris has been designed from the start to support
9verified systems programming through easy interoperability with C and high
9verified systems programming through easy interoperability with C and high
@@ -14,7 +14,7 @@ do notation. Idris also supports tactic based theorem proving, and has a
14lightweight Hugs/GHCI style interface.
14lightweight Hugs/GHCI style interface.
15
15
16Is Idris production ready?
16Is Idris production ready?
17−--------------------------
17+==========================
18
18
19Idris is primarily a research tool for exploring the possibilities of software
19Idris is primarily a research tool for exploring the possibilities of software
20development with dependent types, meaning that the primary goal is not (yet) to
20development with dependent types, meaning that the primary goal is not (yet) to
@@ -29,7 +29,7 @@ limited to) extra library support, polishing the run-time system (and ensuring
29it is robust), providing and maintaining a JVM back end, etc.
29it is robust), providing and maintaining a JVM back end, etc.
30
30
31Why does Idris use eager evaluation rather than lazy?
31Why does Idris use eager evaluation rather than lazy?
32−-----------------------------------------------------
32+=====================================================
33
33
34Idris uses eager evaluation for more predictable performance, in particular
34Idris uses eager evaluation for more predictable performance, in particular
35because one of the longer term goals is to be able to write efficient and
35because one of the longer term goals is to be able to write efficient and
@@ -57,7 +57,7 @@ concrete ``Int``, whereas ``thing_comp`` is a computation which will produce an
57``Int``.
57``Int``.
58
58
59How can I make lazy control structures?
59How can I make lazy control structures?
60−---------------------------------------
60+=======================================
61
61
62You can make control structures using the special Lazy type. For example,
62You can make control structures using the special Lazy type. For example,
63``if...then...else`` is defined as follows in the library:
63``if...then...else`` is defined as follows in the library:
@@ -74,7 +74,7 @@ The type ``Lazy a`` for ``t`` and ``f`` indicates that those arguments will
74only be evaluated if they are used, that is, they are evaluated lazily.
74only be evaluated if they are used, that is, they are evaluated lazily.
75
75
76Evaluation at the REPL doesn't behave as I expect. What's going on?
76Evaluation at the REPL doesn't behave as I expect. What's going on?
77−-------------------------------------------------------------------
77+===================================================================
78
78
79Being a fully dependently typed language, Idris has two phases where it
79Being a fully dependently typed language, Idris has two phases where it
80evaluates things, compile-time and run-time. At compile-time it will only
80evaluates things, compile-time and run-time. At compile-time it will only
@@ -100,14 +100,14 @@ the difference between:
100 \n => \m => plus n (S m) : Nat -> Nat -> Nat
100 \n => \m => plus n (S m) : Nat -> Nat -> Nat
101
101
102When will Idris be self-hosting?
102When will Idris be self-hosting?
103−--------------------------------
103+================================
104
104
105It’s not a priority, though not a bad idea in the long run. It would be a
105It’s not a priority, though not a bad idea in the long run. It would be a
106worthwhile effort in the short term to implement libraries to support
106worthwhile effort in the short term to implement libraries to support
107self-hosting, such as a good parsing library.
107self-hosting, such as a good parsing library.
108
108
109Does Idris have Universe Polymorphism? What is the type of ``Type``?
109Does Idris have Universe Polymorphism? What is the type of ``Type``?
110−--------------------------------------------------------------------
110+====================================================================
111
111
112Rather than Universe polymorphism, Idris has a cumulative hierarchy of
112Rather than Universe polymorphism, Idris has a cumulative hierarchy of
113universes; ``Type : Type 1``, ``Type 1 : Type 2``, etc.
113universes; ``Type : Type 1``, ``Type 1 : Type 2``, etc.
@@ -115,7 +115,7 @@ Cumulativity means that if ``x : Type n`` then also ``x : Type m``,
115provided that ``n <= m``.
115provided that ``n <= m``.
116
116
117Why does Idris use ``Float`` and ``Double`` instead of ``Float32`` and ``Float64``?
117Why does Idris use ``Float`` and ``Double`` instead of ``Float32`` and ``Float64``?
118−------------------------------------------------------------------------------------
118+===================================================================================
119
119
120Historically the C language and many other languages have used the
120Historically the C language and many other languages have used the
121names ``Float`` and ``Double`` to represent floating point numbers of
121names ``Float`` and ``Double`` to represent floating point numbers of
@@ -132,14 +132,14 @@ That is, the names ``Float`` and ``Double`` are used to describe
132single and double precision numbers.
132single and double precision numbers.
133
133
134What does the name ‘Idris’ mean?
134What does the name ‘Idris’ mean?
135−--------------------------------
135+================================
136
136
137British people of a certain age may be familiar with this
137British people of a certain age may be familiar with this
138`singing dragon <https://www.youtube.com/watch?v=G5ZMNyscPcg>`_. If
138`singing dragon <https://www.youtube.com/watch?v=G5ZMNyscPcg>`_. If
139that doesn’t help, maybe you can invent a suitable acronym :-) .
139that doesn’t help, maybe you can invent a suitable acronym :-) .
140
140
141Where can I find more answers?
141Where can I find more answers?
142−------------------------------
142+==============================
143
143
144There is an `Unofficial FAQ
144There is an `Unofficial FAQ
145<https://github.com/idris-lang/Idris-dev/wiki/Unofficial-FAQ>`_ on the wiki on
145<https://github.com/idris-lang/Idris-dev/wiki/Unofficial-FAQ>`_ on the wiki on
docs/guides/type-providers-ffi.rst+12−11
@@ -1,5 +1,6 @@
1+***********************
1Type Providers in Idris
2Type Providers in Idris
2−=======================
3+***********************
3
4
4`Type providers in Idris
5`Type providers in Idris
5<http://www.itu.dk/people/drc/pubs/dependent-type-providers.pdf>`__
6<http://www.itu.dk/people/drc/pubs/dependent-type-providers.pdf>`__
@@ -9,7 +10,7 @@ foreign functions, because these will often be used with type
9providers.
10providers.
10
11
11The use case
12The use case
12−------------
13+============
13
14
14First, let's talk about *why* we might want type providers. There are
15First, let's talk about *why* we might want type providers. There are
15a number of reasons to use them and there are other examples available
16a number of reasons to use them and there are other examples available
@@ -23,7 +24,7 @@ relied upon. We don't just want to hard-code these types into our
23program... so we'll use a type provider to find them at compile time!
24program... so we'll use a type provider to find them at compile time!
24
25
25A simple example
26A simple example
26−----------------
27+================
27
28
28First, let's go over a basic usage of type providers, because foreign
29First, let's go over a basic usage of type providers, because foreign
29functions can be confusing but it's important to remember that
30functions can be confusing but it's important to remember that
@@ -94,7 +95,7 @@ themselves!
94Don't worry, there's a better way.
95Don't worry, there's a better way.
95
96
96Foreign Functions
97Foreign Functions
97−-----------------
98+=================
98
99
99It's actually pretty easy to write a C function that figures out the
100It's actually pretty easy to write a C function that figures out the
100size of ``size_t``:
101size of ``size_t``:
@@ -114,8 +115,8 @@ So now we can get the size of ``size_t`` as long as we're in C code.
114We'd like to be able to use this from Idris. Can we do this? It turns
115We'd like to be able to use this from Idris. Can we do this? It turns
115out we can.
116out we can.
116
117
117−mkForeign
118+``mkForeign``
118−~~~~~~~~~
119+-------------
119
120
120With mkForeign, we can turn a C function into an IO action. It works
121With mkForeign, we can turn a C function into an IO action. It works
121like this:
122like this:
@@ -138,7 +139,7 @@ compiler "Treat the return value of this C function like it's a C int,
138and when you pass it back into Idris, convert it to an Idris int."
139and when you pass it back into Idris, convert it to an Idris int."
139
140
140Caveats of mkForeign
141Caveats of mkForeign
141−^^^^^^^^^^^^^^^^^^^^
142+--------------------
142
143
143First and foremost: ``mkForeign`` is not actually a function. It is
144First and foremost: ``mkForeign`` is not actually a function. It is
144treated specially by the compiler, and there are certain rules you
145treated specially by the compiler, and there are certain rules you
@@ -185,7 +186,7 @@ applied. This is okay:
185 lengths = mapM strlen listOfStrings
186 lengths = mapM strlen listOfStrings
186
187
187Running foreign functions
188Running foreign functions
188−~~~~~~~~~~~~~~~~~~~~~~~~~
189+-------------------------
189
190
190This is all well and good for writing code that will typecheck. To
191This is all well and good for writing code that will typecheck. To
191actually run the code, we'll need to do just a bit more work. Exactly
192actually run the code, we'll need to do just a bit more work. Exactly
@@ -193,7 +194,7 @@ what we need to do depends on whether we want to interpret or compile
193our code.
194our code.
194
195
195In the interpreter
196In the interpreter
196−^^^^^^^^^^^^^^^^^^
197+------------------
197
198
198If we want to call our foreign functions from interpreted code (such
199If we want to call our foreign functions from interpreted code (such
199as the REPL or a type provider), we need to dynamically link a library
200as the REPL or a type provider), we need to dynamically link a library
@@ -213,7 +214,7 @@ functions from an installed library rather than something you wrote
213yourself, the "./" is not necessary.
214yourself, the "./" is not necessary.
214
215
215In an executable
216In an executable
216−^^^^^^^^^^^^^^^^
217+----------------
217
218
218If we want to run our code from an executable, we can statically link
219If we want to run our code from an executable, we can statically link
219instead. We'll use the ``%include`` and ``%link`` directives:
220instead. We'll use the ``%include`` and ``%link`` directives:
@@ -229,7 +230,7 @@ directives search in the current directory by default. (That is, the
229directory from which we run idris.)
230directory from which we run idris.)
230
231
231Putting it all together
232Putting it all together
232−-----------------------
233+=======================
233
234
234So, at the beginning of this article I said we'd use type providers to
235So, at the beginning of this article I said we'd use type providers to
235port ``struct stat`` to Idris. The relevant part is just translating
236port ``struct stat`` to Idris. The relevant part is just translating
docs/index.rst+2−1
@@ -15,6 +15,7 @@ Documentation for the Idris Language
15
15
16 More information concerning the CC0 can be found online at: http://creativecommons.org/publicdomain/zero/1.0/
16 More information concerning the CC0 can be found online at: http://creativecommons.org/publicdomain/zero/1.0/
17
17
18+
18* :ref:`tutorial-index`
19* :ref:`tutorial-index`
19* :ref:`eff-tutorial-index`
20* :ref:`eff-tutorial-index`
20* :ref:`faq-index`
21* :ref:`faq-index`
@@ -47,7 +48,7 @@ The Idris Tutorial
47 tutorial/miscellany
48 tutorial/miscellany
48 tutorial/conclusions
49 tutorial/conclusions
49
50
50−.. _effects:
51+.. _faq:
51
52
52##########################
53##########################
53Frequently Asked Questions
54Frequently Asked Questions
docs/proofs/inductive.rst+6−5
@@ -1,5 +1,6 @@
1+****************
1Inductive Proofs
2Inductive Proofs
2−================
3+****************
3
4
4Before embarking on proving ``plus_commutes`` in Idris itself, let us
5Before embarking on proving ``plus_commutes`` in Idris itself, let us
5consider the overall structure of a proof of some property of natural
6consider the overall structure of a proof of some property of natural
@@ -25,7 +26,7 @@ case). Recalling ``plus``:
25
26
26This is total because it covers all possible inputs (the first argument
27This is total because it covers all possible inputs (the first argument
27can only be ``Z`` or ``S k`` for some ``k``, and the second argument
28can only be ``Z`` or ``S k`` for some ``k``, and the second argument
28−``m`` covers all possible ``Nat``\ s) and in the recursive call, ``k``
29+``m`` covers all possible ``Nat``) and in the recursive call, ``k``
29is structurally smaller than ``S k`` so the first argument will always
30is structurally smaller than ``S k`` so the first argument will always
30reach the base case ``Z`` in any sequence of recursive calls.
31reach the base case ``Z`` in any sequence of recursive calls.
31
32
@@ -50,7 +51,7 @@ function capturing all such inductive definitions:
50.. code-block:: idris
51.. code-block:: idris
51
52
52 nat_induction : (P : Nat -> Type) -> -- Property to show
53 nat_induction : (P : Nat -> Type) -> -- Property to show
53− (P Z) -> -- Base case
54+ (P Z) -> -- Base case
54 ((k : Nat) -> P k -> P (S k)) -> -- Inductive step
55 ((k : Nat) -> P k -> P (S k)) -> -- Inductive step
55 (x : Nat) -> -- Show for all x
56 (x : Nat) -> -- Show for all x
56 P x
57 P x
@@ -63,12 +64,12 @@ version of ``plus``:
63.. code-block:: idris
64.. code-block:: idris
64
65
65 plus_ind : Nat -> Nat -> Nat
66 plus_ind : Nat -> Nat -> Nat
66− plus_ind n m
67+ plus_ind n m
67 = nat_induction (\x => Nat)
68 = nat_induction (\x => Nat)
68 m -- Base case, plus_ind Z m
69 m -- Base case, plus_ind Z m
69 (\k, k_rec => S k_rec) -- Inductive step plus_ind (S k) m
70 (\k, k_rec => S k_rec) -- Inductive step plus_ind (S k) m
70 -- where k_rec = plus_ind k m
71 -- where k_rec = plus_ind k m
71− n
72+ n
72
73
73To prove that ``plus n m = plus m n`` for all natural numbers ``n`` and
74To prove that ``plus n m = plus m n`` for all natural numbers ``n`` and
74``m``, we can also use induction. Either we can fix ``m`` and perform
75``m``, we can also use induction. Either we can fix ``m`` and perform
docs/proofs/interactive.rst+4−5
@@ -1,13 +1,14 @@
1+***************************
1Interactive Theorem Proving
2Interactive Theorem Proving
2−===========================
3+***************************
3
4
4Idris also supports interactive theorem proving via tactics. This
5Idris also supports interactive theorem proving via tactics. This
5−is generally not recommended to be used directly, but rather used as a
6+is generally not recommended to be used directly, but rather used as a
6mechanism for building proof automation which is beyond the scope of this
7mechanism for building proof automation which is beyond the scope of this
7tutorial. In this section, we briefly discus tactics.
8tutorial. In this section, we briefly discus tactics.
8
9
9One way to write proofs interactively is to write the general *structure* of
10One way to write proofs interactively is to write the general *structure* of
10−the proof, and use the interactive mode to complete the details.
11+the proof, and use the interactive mode to complete the details.
11Consider the following definition, proved in :ref:`sect-theorems`:
12Consider the following definition, proved in :ref:`sect-theorems`:
12
13
13.. code-block:: idris
14.. code-block:: idris
@@ -162,5 +163,3 @@ which is trivially provable:
162
163
163Again, we can add this proof to the end of our source file using the
164Again, we can add this proof to the end of our source file using the
164``:addproof`` command at the interactive prompt.
165``:addproof`` command at the interactive prompt.
165−
166−
docs/proofs/patterns.rst+7−6
@@ -1,5 +1,6 @@
1+***********************
1Pattern Matching Proofs
2Pattern Matching Proofs
2−=======================
3+***********************
3
4
4In this section, we will provide a proof of ``plus_commutes`` directly,
5In this section, we will provide a proof of ``plus_commutes`` directly,
5by writing a pattern matching definition. We will use interactive
6by writing a pattern matching definition. We will use interactive
@@ -26,7 +27,7 @@ mapping to Emacs commands.
26
27
27
28
28Creating a Definition
29Creating a Definition
29−---------------------
30+=====================
30
31
31To begin, create a file ``pluscomm.idr`` containing the following type
32To begin, create a file ``pluscomm.idr`` containing the following type
32declaration:
33declaration:
@@ -87,7 +88,7 @@ It is a good idea to give these slightly more meaningful names:
87 plus_commutes (S k) m = ?plus_commutes_S
88 plus_commutes (S k) m = ?plus_commutes_S
88
89
89Base Case
90Base Case
90−---------
91+=========
91
92
92We can create a separate lemma for the base case interactively, by
93We can create a separate lemma for the base case interactively, by
93pressing ``\l`` with the cursor over ``plus_commutes_Z``. This
94pressing ``\l`` with the cursor over ``plus_commutes_Z``. This
@@ -263,7 +264,7 @@ proof, giving:
263The base case is now complete.
264The base case is now complete.
264
265
265Inductive Step
266Inductive Step
266−--------------
267+==============
267
268
268Our main theorem, ``plus_commutes`` should currently be in the following
269Our main theorem, ``plus_commutes`` should currently be in the following
269state:
270state:
@@ -333,9 +334,9 @@ defined by matching on its first argument. The complete definition is:
333 plus_commutes_S k Z = Refl
334 plus_commutes_S k Z = Refl
334 plus_commutes_S k (S j) = rewrite plus_commutes_S k j in Refl
335 plus_commutes_S k (S j) = rewrite plus_commutes_S k j in Refl
335
336
336−All metavariables have now been solved,
337+All metavariables have now been solved,
337
338
338−The ``total`` annotation means that we require the final function to
339+The ``total`` annotation means that we require the final function to
339pass the totality checker; i.e. it will terminate on all possible
340pass the totality checker; i.e. it will terminate on all possible
340well-typed inputs. This is important for proofs, since it provides a
341well-typed inputs. This is important for proofs, since it provides a
341guarantee that the proof is valid in *all* cases, not just those for
342guarantee that the proof is valid in *all* cases, not just those for
docs/proofs/pluscomm.rst+7−6
@@ -1,5 +1,6 @@
1+********************************************
1Running example: Addition of Natural Numbers
2Running example: Addition of Natural Numbers
2−============================================
3+********************************************
3
4
4Throughout this tutorial, we will be working with the following
5Throughout this tutorial, we will be working with the following
5function, defined in the Idris prelude, which defines addition on
6function, defined in the Idris prelude, which defines addition on
@@ -44,7 +45,7 @@ We can use these properties in an Idris program, but in order to do so
44we must *prove* them.
45we must *prove* them.
45
46
46Equality Proofs
47Equality Proofs
47−---------------
48+===============
48
49
49Idris has a built-in propositional equality type, conceptually defined
50Idris has a built-in propositional equality type, conceptually defined
50as follows:
51as follows:
@@ -93,7 +94,7 @@ error:
93 4 = 5 (Expected type)
94 4 = 5 (Expected type)
94
95
95Type checking equality proofs
96Type checking equality proofs
96−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97+-----------------------------
97
98
98An important step in type checking Idris programs is *unification*,
99An important step in type checking Idris programs is *unification*,
99which attempts to resolve implicit arguments such as the implicit
100which attempts to resolve implicit arguments such as the implicit
@@ -123,7 +124,7 @@ following equalities directly:
123 plus_reduces_Sk k m = Refl
124 plus_reduces_Sk k m = Refl
124
125
125Heterogeneous Equality
126Heterogeneous Equality
126−----------------------
127+======================
127
128
128Equality in Idris is *heterogeneous*, meaning that we can even propose
129Equality in Idris is *heterogeneous*, meaning that we can even propose
129equalities between values in different types:
130equalities between values in different types:
@@ -164,7 +165,7 @@ there is only one value which will type check:
164 vect_eq_length xs _ Refl = Refl
165 vect_eq_length xs _ Refl = Refl
165
166
166Properties of ``plus``
167Properties of ``plus``
167−----------------------
168+======================
168
169
169Using the ``(=)`` type, we can now state the properties of ``plus``
170Using the ``(=)`` type, we can now state the properties of ``plus``
170given above as Idris type declarations:
171given above as Idris type declarations:
@@ -185,4 +186,4 @@ the function.) We will also discuss how to use such equality proofs, and
185see where the need for them arises in practice.
186see where the need for them arises in practice.
186
187
187.. [1]
188.. [1]
188− This is known as the Curry-Howard correspondence 
189+ This is known as the Curry-Howard correspondence.
docs/reference/documenting.rst+4−4
@@ -1,8 +1,8 @@
1.. _sect-documenting:
1.. _sect-documenting:
2
2
3−======================
3+**********************
4Documenting Idris Code
4Documenting Idris Code
5−======================
5+**********************
6
6
7Idris documentation comes in two major forms: comments, which exist
7Idris documentation comes in two major forms: comments, which exist
8for a reader’s edification and are ignored by the compiler, and inline
8for a reader’s edification and are ignored by the compiler, and inline
@@ -12,7 +12,7 @@ reference. To consult the documentation for a declaration ``f``, write
12(``C-c C-d`` in Emacs, in Vim).
12(``C-c C-d`` in Emacs, in Vim).
13
13
14Comments
14Comments
15−--------
15+========
16
16
17Use comments to explain why code is written the way that it
17Use comments to explain why code is written the way that it
18is. Idris’s comment syntax is the same as that of Haskell: lines
18is. Idris’s comment syntax is the same as that of Haskell: lines
@@ -22,7 +22,7 @@ lines. These can be used to comment out lines of code or provide
22simple documentation for the readers of Idris code.
22simple documentation for the readers of Idris code.
23
23
24Inline Documentation
24Inline Documentation
25−--------------------
25+====================
26
26
27Idris also supports a comprehensive and rich inline syntax for Idris
27Idris also supports a comprehensive and rich inline syntax for Idris
28code to be generated. This syntax also allows for named parameters and
28code to be generated. This syntax also allows for named parameters and
docs/reference/erasure.rst+21−20
@@ -1,5 +1,6 @@
1+*************************
1Erasure By Usage Analysis
2Erasure By Usage Analysis
2−=========================
3+*************************
3
4
4This work stems from this `feature proposal
5This work stems from this `feature proposal
5<https://github.com/idris-lang/Idris-dev/wiki/Egg-%232%3A-Erasure-annotations>`__
6<https://github.com/idris-lang/Idris-dev/wiki/Egg-%232%3A-Erasure-annotations>`__
@@ -8,7 +9,7 @@ is out of date — and sometimes even in direct contradiction with the
8eventual implementation.
9eventual implementation.
9
10
10Motivation
11Motivation
11−----------
12+==========
12
13
13Traditional dependently typed languages (Agda, Coq) are good at
14Traditional dependently typed languages (Agda, Coq) are good at
14erasing *proofs* (either via irrelevance or an extra universe).
15erasing *proofs* (either via irrelevance or an extra universe).
@@ -52,7 +53,7 @@ The following two sections describe two cases where doing so improves
52the runtime performance asymptotically.
53the runtime performance asymptotically.
53
54
54Binary numbers
55Binary numbers
55−~~~~~~~~~~~~~~
56+--------------
56
57
57- O(n) instead of O(log n)
58- O(n) instead of O(log n)
58
59
@@ -106,7 +107,7 @@ should get rid of them and get runtime code similar to what a idris
106programmer would write.
107programmer would write.
107
108
108U-views of lists
109U-views of lists
109−~~~~~~~~~~~~~~~~
110+----------------
110
111
111- O(n^2) instead of O(n)
112- O(n^2) instead of O(n)
112
113
@@ -141,7 +142,7 @@ linear time — so we need to erase the index ``xs`` if we want to
141achieve this goal.
142achieve this goal.
142
143
143Changes to Idris
144Changes to Idris
144−----------------
145+================
145
146
146Usage analysis is run at every compilation and its outputs are used
147Usage analysis is run at every compilation and its outputs are used
147for various purposes. This is actually invisible to the user but it's
148for various purposes. This is actually invisible to the user but it's
@@ -185,7 +186,7 @@ Postulates are no longer required to be collapsible. They are now
185required to be *unused* instead.
186required to be *unused* instead.
186
187
187Changes to the language
188Changes to the language
188−-----------------------
189+=======================
189
190
190You can use dots to mark fields that are not intended to be used at
191You can use dots to mark fields that are not intended to be used at
191runtime.
192runtime.
@@ -221,7 +222,7 @@ You can also put dots in types of functions to get more guarantees.
221and free implicits are automatically dotted here, too.
222and free implicits are automatically dotted here, too.
222
223
223What it means
224What it means
224−-------------
225+=============
225
226
226Dot annotations serve two purposes:
227Dot annotations serve two purposes:
227
228
@@ -235,7 +236,7 @@ are there mainly to help the programmer (and the compiler) refrain
235from using the values they want to erase.
236from using the values they want to erase.
236
237
237How to use it
238How to use it
238−-------------
239+=============
239
240
240Ideally, few or no extra annotations are needed -- in practice, it
241Ideally, few or no extra annotations are needed -- in practice, it
241turns out that having free implicits automatically dotted is enough to
242turns out that having free implicits automatically dotted is enough to
@@ -250,7 +251,7 @@ compiles to a reasonable binary. Generally, it's sufficient to follow
250erasure warnings (which may be sometimes unhelpful at the moment).
251erasure warnings (which may be sometimes unhelpful at the moment).
251
252
252Benchmarks
253Benchmarks
253−----------
254+==========
254
255
255- source: https://github.com/ziman/idris-benchmarks
256- source: https://github.com/ziman/idris-benchmarks
256- results: http://ziman.functor.sk/erasure-bm/
257- results: http://ziman.functor.sk/erasure-bm/
@@ -258,7 +259,7 @@ Benchmarks
258It can be clearly seen that asymptotics are improved by erasure.
259It can be clearly seen that asymptotics are improved by erasure.
259
260
260Shortcomings
261Shortcomings
261−------------
262+============
262
263
263You can't get warnings in libraries because usage analysis starts from
264You can't get warnings in libraries because usage analysis starts from
264``Main.main``. This will be solved by the planned ``%default_usage``
265``Main.main``. This will be solved by the planned ``%default_usage``
@@ -300,7 +301,7 @@ only if it is unused in every implementation of the method that occurs
300in the program.
301in the program.
301
302
302Planned features
303Planned features
303−----------------
304+================
304
305
305- Fixes to the above shortcomings in general.
306- Fixes to the above shortcomings in general.
306
307
@@ -316,10 +317,10 @@ Planned features
316 in compiled programs.
317 in compiled programs.
317
318
318Troubleshooting
319Troubleshooting
319−---------------
320+===============
320
321
321My program is slower
322My program is slower
322−~~~~~~~~~~~~~~~~~~~~
323+--------------------
323
324
324The patch introducing erasure by usage analysis also disabled some
325The patch introducing erasure by usage analysis also disabled some
325optimisations that were in place before; these are subsumed by the new
326optimisations that were in place before; these are subsumed by the new
@@ -336,14 +337,14 @@ getting compiled into the binary.
336The solution is to change the code so that there are no warnings.
337The solution is to change the code so that there are no warnings.
337
338
338Usage warnings are unhelpful
339Usage warnings are unhelpful
339−~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340+----------------------------
340
341
341This is a known issue and we are working on it. For now, see the section
342This is a known issue and we are working on it. For now, see the section
342`How to read and resolve erasure
343`How to read and resolve erasure
343warnings <#how-to-read-and-resolve-erasure-warnings>`__.
344warnings <#how-to-read-and-resolve-erasure-warnings>`__.
344
345
345There should be no warnings in this function
346There should be no warnings in this function
346−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347+--------------------------------------------
347
348
348A possible cause is non-totality of the function (more precisely,
349A possible cause is non-totality of the function (more precisely,
349non-coverage). If a function is non-covering, the program needs to
350non-coverage). If a function is non-covering, the program needs to
@@ -361,7 +362,7 @@ https://gist.github.com/ziman/10458331). You can either rephrase the
361function or wait until this is fixed, hopefully soon. Fixed.
362function or wait until this is fixed, hopefully soon. Fixed.
362
363
363The compiler refuses to recognise this thing as erased
364The compiler refuses to recognise this thing as erased
364−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365+------------------------------------------------------
365
366
366You can force anything to be erased by wrapping it in the ``Erased``
367You can force anything to be erased by wrapping it in the ``Erased``
367monad. While this program triggers usage warnings,
368monad. While this program triggers usage warnings,
@@ -379,10 +380,10 @@ the following program does not:
379 f g x = g (Erase x) -- OK
380 f g x = g (Erase x) -- OK
380
381
381How to read and resolve erasure warnings
382How to read and resolve erasure warnings
382−----------------------------------------
383+========================================
383
384
384Example 1
385Example 1
385−~~~~~~~~~
386+---------
386
387
387Consider the following program:
388Consider the following program:
388
389
@@ -439,7 +440,7 @@ or fixing ``vlen`` to not use the index:
439Which solution is appropriate depends on the usecase.
440Which solution is appropriate depends on the usecase.
440
441
441Example 2
442Example 2
442−~~~~~~~~~
443+---------
443
444
444Consider the following program manipulating value-indexed binary
445Consider the following program manipulating value-indexed binary
445numbers.
446numbers.
@@ -494,7 +495,7 @@ with every constructor of ``Bin`` and make it a bound implicit:
494 I : {n : Nat} -> bin n -> Bin (1 + n + n)
495 I : {n : Nat} -> bin n -> Bin (1 + n + n)
495
496
496References
497References
497−----------
498+==========
498
499
499.. [BMM04] Edwin Brady, Conor McBride, James McKinna: `Inductive
500.. [BMM04] Edwin Brady, Conor McBride, James McKinna: `Inductive
500 families need not store their indices
501 families need not store their indices
docs/reference/ffi.rst+8−7
@@ -1,5 +1,6 @@
1+******************************
1New Foreign Function Interface
2New Foreign Function Interface
2−==============================
3+******************************
3
4
4.. sectionauthor:: Edwin Brady
5.. sectionauthor:: Edwin Brady
5
6
@@ -19,7 +20,7 @@ are some things you will need to be aware of, which this page
19describes.
20describes.
20
21
21The ``IO'`` monad, and ``main``
22The ``IO'`` monad, and ``main``
22−-------------------------------
23+===============================
23
24
24The ``IO`` monad exists as before, but is now specific to the C
25The ``IO`` monad exists as before, but is now specific to the C
25backend (or, more precisely, any backend whose foreign function calls
26backend (or, more precisely, any backend whose foreign function calls
@@ -61,7 +62,7 @@ function's name, but potentially something more complicated such as an
61external library file or even a URL).
62external library file or even a URL).
62
63
63FFI descriptors
64FFI descriptors
64−---------------
65+===============
65
66
66An FFI descriptor is a record containing a predicate which holds when
67An FFI descriptor is a record containing a predicate which holds when
67a type can be marshalled, and the type of the target of a foreign
68a type can be marshalled, and the type of the target of a foreign
@@ -98,7 +99,7 @@ For C, this is:
98 String -- the name of the C function
99 String -- the name of the C function
99
100
100Foreign calls
101Foreign calls
101−-------------
102+=============
102
103
103To call a foreign function, the ``foreign`` function is used. For
104To call a foreign function, the ``foreign`` function is used. For
104example:
105example:
@@ -134,7 +135,7 @@ example a shorthand for calling external JavaScript functions:
134 jscall fname ty = foreign FFI_JS fname ty
135 jscall fname ty = foreign FFI_JS fname ty
135
136
136FFI implementation
137FFI implementation
137−~~~~~~~~~~~~~~~~~~
138+------------------
138
139
139In order to write bindings to external libraries, the details of how
140In order to write bindings to external libraries, the details of how
140``foreign`` works are unnecessary --- you simply need to know that
141``foreign`` works are unnecessary --- you simply need to know that
@@ -172,7 +173,7 @@ builds the following implicit proof as the ``fty`` argument to
172 FFun C_Str (FFun C_Str (FRet C_Ptr))
173 FFun C_Str (FFun C_Str (FRet C_Ptr))
173
174
174Compiling foreign calls
175Compiling foreign calls
175−-----------------------
176+=======================
176
177
177(This section assumes some knowledge of the Idris internals.)
178(This section assumes some knowledge of the Idris internals.)
178
179
@@ -232,7 +233,7 @@ to marshal the arguments and return value appropriately.
232 the function ``toFType``, to see how this works in practice.
233 the function ``toFType``, to see how this works in practice.
233
234
234JavaScript FFI descriptor
235JavaScript FFI descriptor
235−~~~~~~~~~~~~~~~~~~~~~~~~~
236+=========================
236
237
237The JavaScript FFI descriptor is a little more complex, because the
238The JavaScript FFI descriptor is a little more complex, because the
238JavaScript FFI supports marshalling functions. It is defined as
239JavaScript FFI supports marshalling functions. It is defined as
docs/reference/uniqueness-types.rst+5−4
@@ -1,5 +1,6 @@
1+****************
1Uniqueness Types
2Uniqueness Types
2−================
3+****************
3
4
4Uniqueness Types are an experimental feature available from Idris
5Uniqueness Types are an experimental feature available from Idris
50.9.15. A value with a unique type is guaranteed to have *at most one*
60.9.15. A value with a unique type is guaranteed to have *at most one*
@@ -25,7 +26,7 @@ include:
25 allocate
26 allocate
26
27
27Using Uniqueness
28Using Uniqueness
28−~~~~~~~~~~~~~~~~
29+================
29
30
30If ``x : T`` and ``T : UniqueType``, then there is at most one reference
31If ``x : T`` and ``T : UniqueType``, then there is at most one reference
31to ``x`` at any time during run-time execution. For example, we can
32to ``x`` at any time during run-time execution. For example, we can
@@ -129,7 +130,7 @@ such a function may be passed a ``UniqueType``, any value of type
129once on the right hand side.
130once on the right hand side.
130
131
131Borrowed Types
132Borrowed Types
132−~~~~~~~~~~~~~~
133+--------------
133
134
134It quickly becomes obvious when working with uniqueness types that
135It quickly becomes obvious when working with uniqueness types that
135having only one reference at a time can be painful. For example, what
136having only one reference at a time can be painful. For example, what
@@ -227,7 +228,7 @@ therefore write ``showU`` as follows:
227 showU' (x :: xs) = show x ++ ", " ++ showU' xs
228 showU' (x :: xs) = show x ++ ", " ++ showU' xs
228
229
229Problems/Disadvantages/Still to do...
230Problems/Disadvantages/Still to do...
230−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231+-------------------------------------
231
232
232This is a work in progress, there is lots to do. The most obvious
233This is a work in progress, there is lots to do. The most obvious
233problem is the loss of abstraction. On the one hand, we have more
234problem is the loss of abstraction. On the one hand, we have more
docs/tutorial/classes.rst+12−12
@@ -1,8 +1,8 @@
1.. _sect-classes:
1.. _sect-classes:
2
2
3−============
3+************
4Type Classes
4Type Classes
5−============
5+************
6
6
7We often want to define functions which work across several different
7We often want to define functions which work across several different
8data types. For example, we would like arithmetic operators to work on
8data types. For example, we would like arithmetic operators to work on
@@ -65,7 +65,7 @@ going to use it to convert each element to a ``String``:
65 show' (x :: xs) = show x ++ ", " ++ show' xs
65 show' (x :: xs) = show x ++ ", " ++ show' xs
66
66
67Default Definitions
67Default Definitions
68−-------------------
68+===================
69
69
70The library defines an ``Eq`` class which provides an interface for
70The library defines an ``Eq`` class which provides an interface for
71comparing values for equality or inequality, with instances for all of
71comparing values for equality or inequality, with instances for all of
@@ -110,7 +110,7 @@ definition is missing, and there is a default definition for it, then
110the default is used instead.
110the default is used instead.
111
111
112Extending Classes
112Extending Classes
113−-----------------
113+=================
114
114
115Classes can also be extended. A logical next step from an equality
115Classes can also be extended. A logical next step from an equality
116relation ``Eq`` is to define an ordering relation ``Ord``. We can
116relation ``Eq`` is to define an ordering relation ``Ord``. We can
@@ -155,7 +155,7 @@ separated list, for example:
155 sortAndShow xs = show (sort xs)
155 sortAndShow xs = show (sort xs)
156
156
157Functors and Applicatives
157Functors and Applicatives
158−-------------------------
158+=========================
159
159
160So far, we have seen single parameter type classes, where the parameter
160So far, we have seen single parameter type classes, where the parameter
161is of type ``Type``. In general, there can be any number (greater than
161is of type ``Type``. In general, there can be any number (greater than
@@ -195,7 +195,7 @@ abstracts the notion of function application:
195 (<*>) : f (a -> b) -> f a -> f b
195 (<*>) : f (a -> b) -> f a -> f b
196
196
197Monads and ``do``-notation
197Monads and ``do``-notation
198−--------------------------
198+==========================
199
199
200The ``Monad`` class allows us to encapsulate binding and computation,
200The ``Monad`` class allows us to encapsulate binding and computation,
201and is the basis of ``do``-notation introduced in Section
201and is the basis of ``do``-notation introduced in Section
@@ -248,7 +248,7 @@ are available, or return ``Nothing`` if they are not. Managing the
248 Nothing : Maybe Int
248 Nothing : Maybe Int
249
249
250``!``-notation
250``!``-notation
251−~~~~~~~~~~~~~~
251+--------------
252
252
253In many cases, using ``do``-notation can make programs unnecessarily
253In many cases, using ``do``-notation can make programs unnecessarily
254verbose, particularly in cases such as ``m_add`` above where the value
254verbose, particularly in cases such as ``m_add`` above where the value
@@ -292,7 +292,7 @@ is lifted to:
292 f g'
292 f g'
293
293
294Monad comprehensions
294Monad comprehensions
295−~~~~~~~~~~~~~~~~~~~~
295+--------------------
296
296
297The list comprehension notation we saw in Section
297The list comprehension notation we saw in Section
298:ref:`sect-more-expr` is more general, and applies to anything which
298:ref:`sect-more-expr` is more general, and applies to anything which
@@ -336,7 +336,7 @@ would be:
336 m_add x y = [ x' + y' | x' <- x, y' <- y ]
336 m_add x y = [ x' + y' | x' <- x, y' <- y ]
337
337
338Idiom brackets
338Idiom brackets
339−--------------
339+==============
340
340
341While ``do`` notation gives an alternative meaning to sequencing,
341While ``do`` notation gives an alternative meaning to sequencing,
342idioms give an alternative meaning to *application*. The notation and
342idioms give an alternative meaning to *application*. The notation and
@@ -386,7 +386,7 @@ application ``[| f a1 …an |]`` is translated into ``pure f <> a1 <>
386 m_add' x y = [| x + y |]
386 m_add' x y = [| x + y |]
387
387
388An error-handling interpreter
388An error-handling interpreter
389−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389+-----------------------------
390
390
391Idiom notation is commonly useful when defining evaluators. McBride
391Idiom notation is commonly useful when defining evaluators. McBride
392and Paterson describe such an evaluator [1]_, for a language similar
392and Paterson describe such an evaluator [1]_, for a language similar
@@ -455,7 +455,7 @@ to handle errors:
455 MkEval envFn => envFn env
455 MkEval envFn => envFn env
456
456
457Named Instances
457Named Instances
458−---------------
458+===============
459
459
460It can be desirable to have multiple instances of a type class, for
460It can be desirable to have multiple instances of a type class, for
461example to provide alternative methods for sorting or printing values.
461example to provide alternative methods for sorting or printing values.
@@ -492,7 +492,7 @@ instance ``myord`` as follows, at the Idris prompt:
492
492
493
493
494Determining Parameters
494Determining Parameters
495−----------------------
495+======================
496
496
497When a class has more than one parameter, it can help resolution if
497When a class has more than one parameter, it can help resolution if
498the parameters used to resolve the type class are restricted. For
498the parameters used to resolve the type class are restricted. For
docs/tutorial/conclusions.rst+2−2
@@ -1,8 +1,8 @@
1.. _sect-concs:
1.. _sect-concs:
2
2
3−===============
3+***************
4Further Reading
4Further Reading
5−===============
5+***************
6
6
7Further information about Idris programming, and programming with
7Further information about Idris programming, and programming with
8dependent types in general, can be obtained from various sources:
8dependent types in general, can be obtained from various sources:
docs/tutorial/index.rst+3−3
@@ -1,8 +1,8 @@
1.. _tutorial-index:
1.. _tutorial-index:
2
2
3−####################
3+##################
4− The Idris Tutorial
4+The Idris Tutorial
5−####################
5+##################
6
6
7The is the Idris Tutorial. It will teach you about programming in the Idris Language.
7The is the Idris Tutorial. It will teach you about programming in the Idris Language.
8
8
docs/tutorial/interactive.rst+10−10
@@ -1,8 +1,8 @@
1.. _sect-interactive:
1.. _sect-interactive:
2
2
3−===================
3+*******************
4Interactive Editing
4Interactive Editing
5−===================
5+*******************
6
6
7By now, we have seen several examples of how Idris’ dependent type
7By now, we have seen several examples of how Idris’ dependent type
8system can give extra confidence in a function’s correctness by giving
8system can give extra confidence in a function’s correctness by giving
@@ -25,7 +25,7 @@ available.
25
25
26
26
27Editing at the REPL
27Editing at the REPL
28−-------------------
28+===================
29
29
30The REPL provides a number of commands, which we will describe
30The REPL provides a number of commands, which we will describe
31shortly, which generate new program fragments based on the currently
31shortly, which generate new program fragments based on the currently
@@ -59,10 +59,10 @@ A text editor can take advantage of this, along with the editing
59commands, in order to provide interactive editing support.
59commands, in order to provide interactive editing support.
60
60
61Editing Commands
61Editing Commands
62−----------------
62+================
63
63
64:addclause
64:addclause
65−~~~~~~~~~~
65+----------
66
66
67The ``:addclause n f`` command (abbreviated ``:ac n f``) creates a
67The ``:addclause n f`` command (abbreviated ``:ac n f``) creates a
68template definition for the function named ``f`` declared on line
68template definition for the function named ``f`` declared on line
@@ -91,7 +91,7 @@ This declares that any names generated for types in the ``Vect`` family
91should be chosen in the order ``xs``, ``ys``, ``zs``, ``ws``.
91should be chosen in the order ``xs``, ``ys``, ``zs``, ``ws``.
92
92
93:casesplit
93:casesplit
94−~~~~~~~~~~
94+----------
95
95
96The ``:casesplit n x`` command, abbreviated ``:cs n x``, splits the
96The ``:casesplit n x`` command, abbreviated ``:cs n x``, splits the
97pattern variable ``x`` on line ``n`` into the various pattern forms it
97pattern variable ``x`` on line ``n`` into the various pattern forms it
@@ -125,7 +125,7 @@ That is, the pattern variable ``ys`` has been split into one case
125ys`` would lead to a unification error.
125ys`` would lead to a unification error.
126
126
127:addmissing
127:addmissing
128−~~~~~~~~~~~
128+-----------
129
129
130The ``:addmissing n f`` command, abbreviated ``:am n f``, adds the
130The ``:addmissing n f`` command, abbreviated ``:am n f``, adds the
131clauses which are required to make the function ``f`` on line ``n``
131clauses which are required to make the function ``f`` on line ``n``
@@ -148,7 +148,7 @@ generates the required clauses, and eliminates the clauses which would
148lead to unification errors.
148lead to unification errors.
149
149
150:proofsearch
150:proofsearch
151−~~~~~~~~~~~~
151+------------
152
152
153The ``:proofsearch n f`` command, abbreviated ``:ps n f``, attempts to
153The ``:proofsearch n f`` command, abbreviated ``:ps n f``, attempts to
154find a value for the metavariable ``f`` on line ``n`` by proof search,
154find a value for the metavariable ``f`` on line ``n`` by proof search,
@@ -186,7 +186,7 @@ must have type ``c`` and the only way to get this is to apply ``f`` to
186recursively.
186recursively.
187
187
188:makewith
188:makewith
189−~~~~~~~~~
189+---------
190
190
191The ``:makewith n f`` command, abbreviated ``:mw n f``, adds a
191The ``:makewith n f`` command, abbreviated ``:mw n f``, adds a
192``with`` to a pattern clause. For example, recall ``parity``. If line
192``with`` to a pattern clause. For example, recall ``parity``. If line
@@ -219,7 +219,7 @@ dependent pattern matching by showing a programmer exactly what the
219valid patterns are.
219valid patterns are.
220
220
221Interactive Editing in Vim
221Interactive Editing in Vim
222−--------------------------
222+==========================
223
223
224The editor mode for Vim provides syntax highlighting, indentation and
224The editor mode for Vim provides syntax highlighting, indentation and
225interactive editing support using the commands described above.
225interactive editing support using the commands described above.
docs/tutorial/interp.rst+7−7
@@ -1,8 +1,8 @@
1.. _sect-interp:
1.. _sect-interp:
2
2
3−===================================
3+***********************************
4Example: The Well-Typed Interpreter
4Example: The Well-Typed Interpreter
5−===================================
5+***********************************
6
6
7In this section, we’ll use the features we’ve seen so far to write a
7In this section, we’ll use the features we’ve seen so far to write a
8larger example, an interpreter for a simple functional programming
8larger example, an interpreter for a simple functional programming
@@ -12,7 +12,7 @@ system to ensure that any programs which can be represented are
12well-typed.
12well-typed.
13
13
14Representing Languages
14Representing Languages
15−----------------------
15+======================
16
16
17First, let us define the types in the language. We have integers,
17First, let us define the types in the language. We have integers,
18booleans, and functions, represented by ``Ty``:
18booleans, and functions, represented by ``Ty``:
@@ -140,7 +140,7 @@ that only the branch which is taken need be evaluated:
140 Expr G a
140 Expr G a
141
141
142Writing the Interpreter
142Writing the Interpreter
143−-----------------------
143+=======================
144
144
145When we evaluate an ``Expr``, we’ll need to know the values in scope,
145When we evaluate an ``Expr``, we’ll need to know the values in scope,
146as well as their types. ``Env`` is an environment, indexed over the
146as well as their types. ``Env`` is an environment, indexed over the
@@ -225,7 +225,7 @@ its operands directly, and for ``If``, we apply the Idris
225 else interp env e
225 else interp env e
226
226
227Testing
227Testing
228−-------
228+=======
229
229
230We can make some simple test functions. Firstly, adding two inputs
230We can make some simple test functions. Firstly, adding two inputs
231``\x. \y. y + x`` is written as follows:
231``\x. \y. y + x`` is written as follows:
@@ -248,7 +248,7 @@ can be written as:
248 (Var Stop)))
248 (Var Stop)))
249
249
250Running
250Running
251−-------
251+=======
252
252
253To finish, we write a ``main`` program which interprets the factorial
253To finish, we write a ``main`` program which interprets the factorial
254function on user input:
254function on user input:
@@ -271,7 +271,7 @@ program at the Idris interactive environment is:
271
271
272
272
273Aside: ``cast``
273Aside: ``cast``
274−~~~~~~~~~~~~~~~
274+---------------
275
275
276The prelude defines a type class ``Cast`` which allows conversion
276The prelude defines a type class ``Cast`` which allows conversion
277between types:
277between types:
docs/tutorial/introduction.rst+4−4
@@ -1,8 +1,8 @@
1.. _sect-intro:
1.. _sect-intro:
2
2
3−============
3+************
4Introduction
4Introduction
5−============
5+************
6
6
7In conventional programming languages, there is a clear distinction
7In conventional programming languages, there is a clear distinction
8between *types* and *values*. For example, in `Haskell
8between *types* and *values*. For example, in `Haskell
@@ -44,7 +44,7 @@ a lightweight foreign function interface which allows easy interaction
44with external ``C`` libraries.
44with external ``C`` libraries.
45
45
46Intended Audience
46Intended Audience
47−-----------------
47+=================
48
48
49This tutorial is intended as a brief introduction to the language, and
49This tutorial is intended as a brief introduction to the language, and
50is aimed at readers already familiar with a functional language such
50is aimed at readers already familiar with a functional language such
@@ -55,7 +55,7 @@ briefly. The reader is also assumed to have some interest in using
55dependent types for writing and verifying systems software.
55dependent types for writing and verifying systems software.
56
56
57Example Code
57Example Code
58−------------
58+============
59
59
60This tutorial includes some example code, which has been tested with
60This tutorial includes some example code, which has been tested with
61Idris version . The files are available in the Idris
61Idris version . The files are available in the Idris
docs/tutorial/miscellany.rst+17−17
@@ -1,8 +1,8 @@
1.. _sect-misc:
1.. _sect-misc:
2
2
3−==========
3+**********
4Miscellany
4Miscellany
5−==========
5+**********
6
6
7In this section we discuss a variety of additional features:
7In this section we discuss a variety of additional features:
8
8
@@ -15,7 +15,7 @@ In this section we discuss a variety of additional features:
15+ the universe hierarchy.
15+ the universe hierarchy.
16
16
17Auto implicit arguments
17Auto implicit arguments
18−-----------------------
18+=======================
19
19
20We have already seen implicit arguments, which allows arguments to be
20We have already seen implicit arguments, which allows arguments to be
21omitted when they can be inferred by the type checker, e.g.
21omitted when they can be inferred by the type checker, e.g.
@@ -70,7 +70,7 @@ to:
70 head (x :: xs) = x
70 head (x :: xs) = x
71
71
72Implicit conversions
72Implicit conversions
73−--------------------
73+====================
74
74
75Idris supports the creation of *implicit conversions*, which allow
75Idris supports the creation of *implicit conversions*, which allow
76automatic conversion of values from one type to another when required to
76automatic conversion of values from one type to another when required to
@@ -99,7 +99,7 @@ specific language, or to hide details of a proof. Such examples are
99beyond the scope of this tutorial.
99beyond the scope of this tutorial.
100
100
101Literate programming
101Literate programming
102−--------------------
102+====================
103
103
104Like Haskell, Idris supports *literate* programming. If a file has
104Like Haskell, Idris supports *literate* programming. If a file has
105an extension of ``.lidr`` then it is assumed to be a literate file. In
105an extension of ``.lidr`` then it is assumed to be a literate file. In
@@ -120,7 +120,7 @@ program line (beginning with ``>``) and a comment line (beginning with
120any other character).
120any other character).
121
121
122Foreign function calls
122Foreign function calls
123−----------------------
123+======================
124
124
125For practical programming, it is often necessary to be able to use
125For practical programming, it is often necessary to be able to use
126external libraries, particularly for interfacing with the operating
126external libraries, particularly for interfacing with the operating
@@ -191,7 +191,7 @@ function is implemented as follows, as a call to an external function
191 putStr x = mkForeign (FFun "putStr" [FString] FUnit) x
191 putStr x = mkForeign (FFun "putStr" [FString] FUnit) x
192
192
193Include and linker directives
193Include and linker directives
194−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194+-----------------------------
195
195
196Foreign function calls are translated directly to calls to C functions,
196Foreign function calls are translated directly to calls to C functions,
197with appropriate conversion between the Idris representation of a
197with appropriate conversion between the Idris representation of a
@@ -215,7 +215,7 @@ through the following directives:
215 object ``x.so``.
215 object ``x.so``.
216
216
217Testing foreign function calls
217Testing foreign function calls
218−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218+------------------------------
219
219
220Normally, the Idris interpreter (used for typechecking and at the REPL)
220Normally, the Idris interpreter (used for typechecking and at the REPL)
221will not perform IO actions. Additionally, as it neither generates C
221will not perform IO actions. Additionally, as it neither generates C
@@ -232,7 +232,7 @@ command or the ``%dynamic`` directive. For example:
232 0.9995736030415051 : Float
232 0.9995736030415051 : Float
233
233
234Type Providers
234Type Providers
235−--------------
235+==============
236
236
237Idris type providers, inspired by F#’s type providers, are a means of
237Idris type providers, inspired by F#’s type providers, are a means of
238making our types be “about” something in the world outside of Idris. For
238making our types be “about” something in the world outside of Idris. For
@@ -301,7 +301,7 @@ provider implementations, including a statically-checked SQLite binding,
301are available in an external collection [1]_.
301are available in an external collection [1]_.
302
302
303C Target
303C Target
304−--------
304+========
305
305
306The default target of Idris is C. Compiling via :
306The default target of Idris is C. Compiling via :
307
307
@@ -341,14 +341,14 @@ is shown below :
341 putStrLn $ show $ factorial 3
341 putStrLn $ show $ factorial 3
342
342
343JavaScript Target
343JavaScript Target
344−-----------------
344+=================
345
345
346Idris is capable of producing *JavaScript* code that can be run in a
346Idris is capable of producing *JavaScript* code that can be run in a
347browser as well as in the *NodeJS* environment or alike. One can use the
347browser as well as in the *NodeJS* environment or alike. One can use the
348FFI to communicate with the *JavaScript* ecosystem.
348FFI to communicate with the *JavaScript* ecosystem.
349
349
350Code Generation
350Code Generation
351−~~~~~~~~~~~~~~~
351+---------------
352
352
353Code generation is split into two separate targets. To generate code
353Code generation is split into two separate targets. To generate code
354that is tailored for running in the browser issue the following command:
354that is tailored for running in the browser issue the following command:
@@ -375,7 +375,7 @@ automatically add a newline to the end of each string. This behaviour
375does not show up in the *NodeJS* code generator.
375does not show up in the *NodeJS* code generator.
376
376
377Using the FFI
377Using the FFI
378−~~~~~~~~~~~~~
378+-------------
379
379
380To write a useful application we need to communicate with the outside
380To write a useful application we need to communicate with the outside
381world. Maybe we want to manipulate the DOM or send an Ajax request. For
381world. Maybe we want to manipulate the DOM or send an Ajax request. For
@@ -441,7 +441,7 @@ program:
441The program outputs ``3``, just like we expected.
441The program outputs ``3``, just like we expected.
442
442
443Including external *JavaScript* files
443Including external *JavaScript* files
444−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444+-------------------------------------
445
445
446Whenever one is working with *JavaScript* one might want to include
446Whenever one is working with *JavaScript* one might want to include
447external libraries or just some functions that she or he wants to call
447external libraries or just some functions that she or he wants to call
@@ -470,7 +470,7 @@ And for use in the browser:
470The given files will be added to the top of the generated code.
470The given files will be added to the top of the generated code.
471
471
472Including *NodeJS* modules
472Including *NodeJS* modules
473−~~~~~~~~~~~~~~~~~~~~~~~~~~
473+--------------------------
474
474
475The *NodeJS* code generator can also include modules with the ``%lib``
475The *NodeJS* code generator can also include modules with the ``%lib``
476directive.
476directive.
@@ -486,7 +486,7 @@ This directive compiles into the following *JavaScript*
486 var fs = require("fs");
486 var fs = require("fs");
487
487
488Shrinking down generated *JavaScript*
488Shrinking down generated *JavaScript*
489−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489+-------------------------------------
490
490
491Idris can produce very big chunks of *JavaScript* code. However, the
491Idris can produce very big chunks of *JavaScript* code. However, the
492generated code can be minified using the ``closure-compiler`` from
492generated code can be minified using the ``closure-compiler`` from
@@ -497,7 +497,7 @@ and it’s highly recommended to use it when shipping a *JavaScript*
497application written in Idris.
497application written in Idris.
498
498
499Cumulativity
499Cumulativity
500−------------
500+============
501
501
502Since values can appear in types and *vice versa*, it is natural that
502Since values can appear in types and *vice versa*, it is natural that
503types themselves have types. For example:
503types themselves have types. For example:
docs/tutorial/modules.rst+5−5
@@ -1,8 +1,8 @@
1.. _sect-namespaces:
1.. _sect-namespaces:
2
2
3−=======================
3+**********************
4Modules and Namespaces
4Modules and Namespaces
5−=======================
5+**********************
6
6
7An Idris program consists of a collection of modules. Each module
7An Idris program consists of a collection of modules. Each module
8includes an optional ``module`` declaration giving the name of the
8includes an optional ``module`` declaration giving the name of the
@@ -72,7 +72,7 @@ main module, with the ``main`` function, must be called
72``Main``—although its filename need not be ``Main.idr``.
72``Main``—although its filename need not be ``Main.idr``.
73
73
74Export Modifiers
74Export Modifiers
75−----------------
75+================
76
76
77By default, all names defined in a module are exported for use by other
77By default, all names defined in a module are exported for use by other
78modules. However, it is good practice only to export a minimal interface
78modules. However, it is good practice only to export a minimal interface
@@ -146,7 +146,7 @@ abstract names in module ``C``, but will not re-export anything from
146module ``B``.
146module ``B``.
147
147
148Explicit Namespaces
148Explicit Namespaces
149−-------------------
149+===================
150
150
151Defining a module also defines a namespace implicitly. However,
151Defining a module also defines a namespace implicitly. However,
152namespaces can also be given *explicitly*. This is most useful if you
152namespaces can also be given *explicitly*. This is most useful if you
@@ -176,7 +176,7 @@ disambiguated by their types:
176 "foofoo" : String
176 "foofoo" : String
177
177
178Parameterised blocks
178Parameterised blocks
179−--------------------
179+====================
180
180
181Groups of functions can be parameterised over a number of arguments
181Groups of functions can be parameterised over a number of arguments
182using a ``parameters`` declaration, for example:
182using a ``parameters`` declaration, for example:
docs/tutorial/packages.rst+4−4
@@ -1,8 +1,8 @@
1.. _sect-packages:
1.. _sect-packages:
2
2
3−========
3+********
4Packages
4Packages
5−========
5+********
6
6
7Idris includes a simple system for building packages from a
7Idris includes a simple system for building packages from a
8package description file. These files can be used with the Idris
8package description file. These files can be used with the Idris
@@ -10,7 +10,7 @@ compiler to manage the development process of your Idris
10programmes and packages.
10programmes and packages.
11
11
12Package Descriptions
12Package Descriptions
13−--------------------
13+====================
14
14
15A package description includes the following:
15A package description includes the following:
16
16
@@ -58,7 +58,7 @@ external ``C`` libraries, the following options are available:
58 object files to be installed, perhaps generated by the ``Makefile``.
58 object files to be installed, perhaps generated by the ``Makefile``.
59
59
60Using Package files
60Using Package files
61−-------------------
61+===================
62
62
63Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
63Given an Idris package file ``text.ipkg`` it can be used with the Idris compiler as follows:
64
64
docs/tutorial/provisional.rst+5−5
@@ -1,8 +1,8 @@
1.. _sect-provisional:
1.. _sect-provisional:
2
2
3−=======================
3+***********************
4Provisional Definitions
4Provisional Definitions
5−=======================
5+***********************
6
6
7Sometimes when programming with dependent types, the type required by
7Sometimes when programming with dependent types, the type required by
8the type checker and the type of the program we have written will be
8the type checker and the type of the program we have written will be
@@ -54,7 +54,7 @@ reduction. These values are obviously equal — how can we rewrite the
54program to fix this problem?
54program to fix this problem?
55
55
56Provisional definitions
56Provisional definitions
57−-----------------------
57+=======================
58
58
59*Provisional definitions* help with this problem by allowing us to defer
59*Provisional definitions* help with this problem by allowing us to defer
60the proof details until a later point. There are two main reasons why
60the proof details until a later point. There are two main reasons why
@@ -159,7 +159,7 @@ reversed:
159 "[False, True, False, True, False, True]" : String
159 "[False, True, False, True, False, True]" : String
160
160
161Suspension of Disbelief
161Suspension of Disbelief
162−-----------------------
162+=======================
163
163
164Idris requires that proofs be complete before compiling programs
164Idris requires that proofs be complete before compiling programs
165(although evaluation at the prompt is possible without proof details).
165(although evaluation at the prompt is possible without proof details).
@@ -192,7 +192,7 @@ The ``exact`` tactic allows us to provide an exact value for the proof.
192In this case, we assert that the value we gave was correct.
192In this case, we assert that the value we gave was correct.
193
193
194Example: Binary numbers
194Example: Binary numbers
195−-----------------------
195+=======================
196
196
197Previously, we implemented conversion to binary numbers using the
197Previously, we implemented conversion to binary numbers using the
198``Parity`` view. Here, we show how to use the same view to implement a
198``Parity`` view. Here, we show how to use the same view to implement a
docs/tutorial/starting.rst+5−5
@@ -1,11 +1,11 @@
1.. _sect-starting:
1.. _sect-starting:
2
2
3−===============
3+***************
4Getting Started
4Getting Started
5−===============
5+***************
6
6
7Prerequisites
7Prerequisites
8−-------------
8+=============
9
9
10Before installing Idris, you will need to make sure you have all
10Before installing Idris, you will need to make sure you have all
11of the necessary libraries and tools. You will need:
11of the necessary libraries and tools. You will need:
@@ -18,7 +18,7 @@ of the necessary libraries and tools. You will need:
18 from MacPorts/Homebrew and all major Linux distributions.
18 from MacPorts/Homebrew and all major Linux distributions.
19
19
20Downloading and Installing
20Downloading and Installing
21−--------------------------
21+==========================
22
22
23The easiest way to install Idris, if you have all of the
23The easiest way to install Idris, if you have all of the
24prerequisites, is to type:
24prerequisites, is to type:
@@ -69,7 +69,7 @@ instead. Some useful options to the Idris command are:
69- ``--help`` display usage summary and command line options
69- ``--help`` display usage summary and command line options
70
70
71The Interactive Environment
71The Interactive Environment
72−---------------------------
72+===========================
73
73
74Entering ``idris`` at the shell prompt starts up the interactive
74Entering ``idris`` at the shell prompt starts up the interactive
75environment. You should see something like the following:
75environment. You should see something like the following:
docs/tutorial/syntax.rst+11−8
@@ -1,14 +1,17 @@
1+.. _sect-syntax:
2+
3+*****************
1Syntax Extensions
4Syntax Extensions
2−=================
5+*****************
3
6
4−supports the implementation of *Embedded Domain Specific Languages*
7+Idris supports the implementation of *Embedded Domain Specific
5−(EDSLs) in several ways [1]_. One way, as we have already seen, is
8+Languages* (EDSLs) in several ways [1]_. One way, as we have already
6−through extending ``do`` notation. Another important way is to allow
9+seen, is through extending ``do`` notation. Another important way is
7−extension of the core syntax. In this section we describe two ways of
10+to allow extension of the core syntax. In this section we describe two
8−extending the syntax: ``syntax`` rules and ``dsl`` notation.
11+ways of extending the syntax: ``syntax`` rules and ``dsl`` notation.
9
12
10``syntax`` rules
13``syntax`` rules
11−----------------
14+================
12
15
13We have seen ``if...then...else`` expressions, but these are not built
16We have seen ``if...then...else`` expressions, but these are not built
14in. Instead, we can define a function in the prelude as follows (we
17in. Instead, we can define a function in the prelude as follows (we
@@ -101,7 +104,7 @@ a bound variable, substituted on the right hand side. We have also put
101``in`` in quotation marks since it is already a reserved word.
104``in`` in quotation marks since it is already a reserved word.
102
105
103``dsl`` notation
106``dsl`` notation
104−----------------
107+================
105
108
106The well-typed interpreter in Section :ref:`sect-interp` is a simple
109The well-typed interpreter in Section :ref:`sect-interp` is a simple
107example of a common programming pattern with dependent types. Namely:
110example of a common programming pattern with dependent types. Namely:
docs/tutorial/theorems.rst+12−12
@@ -1,11 +1,11 @@
1.. _sect-theorems:
1.. _sect-theorems:
2
2
3−===============
3+***************
4Theorem Proving
4Theorem Proving
5−===============
5+***************
6
6
7Equality
7Equality
8−--------
8+========
9
9
10Idris allows propositional equalities to be declared, allowing theorems about
10Idris allows propositional equalities to be declared, allowing theorems about
11programs to be stated and proved. Equality is built in, but conceptually
11programs to be stated and proved. Equality is built in, but conceptually
@@ -31,7 +31,7 @@ For example:
31.. _sect-empty:
31.. _sect-empty:
32
32
33The Empty Type
33The Empty Type
34−--------------
34+==============
35
35
36There is an empty type, :math:`\bot`, which has no constructors. It is
36There is an empty type, :math:`\bot`, which has no constructors. It is
37therefore impossible to construct an element of the empty type, at least
37therefore impossible to construct an element of the empty type, at least
@@ -64,7 +64,7 @@ contradiction.
64 void : Void -> a
64 void : Void -> a
65
65
66Simple Theorems
66Simple Theorems
67−---------------
67+===============
68
68
69When type checking dependent types, the type itself gets *normalised*.
69When type checking dependent types, the type itself gets *normalised*.
70So imagine we want to prove the following theorem about the reduction
70So imagine we want to prove the following theorem about the reduction
@@ -116,16 +116,16 @@ We can do the same for the reduction behaviour of plus on successors:
116Even for trival theorems like these, the proofs are a little tricky to
116Even for trival theorems like these, the proofs are a little tricky to
117construct in one go. When things get even slightly more complicated, it
117construct in one go. When things get even slightly more complicated, it
118becomes too much to think about to construct proofs in this ‘batch
118becomes too much to think about to construct proofs in this ‘batch
119−mode’.
119+mode’.
120
120
121Idris provides interactive editing capabilities, which can help with
121Idris provides interactive editing capabilities, which can help with
122building proofs. For more details on building proofs interactively in
122building proofs. For more details on building proofs interactively in
123−an editor, see :ref:`proofs-index`.
123+an editor, see :ref:`proofs-index`.
124
124
125.. _sect-totality:
125.. _sect-totality:
126
126
127Totality Checking
127Totality Checking
128−-----------------
128+=================
129
129
130If we really want to trust our proofs, it is important that they are
130If we really want to trust our proofs, it is important that they are
131defined by *total* functions — that is, a function which is defined for
131defined by *total* functions — that is, a function which is defined for
@@ -195,7 +195,7 @@ total, a function ``f`` must:
195- Not call any non-total functions
195- Not call any non-total functions
196
196
197Directives and Compiler Flags for Totality
197Directives and Compiler Flags for Totality
198−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198+------------------------------------------
199
199
200By default, Idris allows all well-typed definitions, whether total or not.
200By default, Idris allows all well-typed definitions, whether total or not.
201However, it is desirable for functions to be total as far as possible, as this
201However, it is desirable for functions to be total as far as possible, as this
@@ -216,7 +216,7 @@ Finally, the compiler flag ``--warnpartial`` causes to print a warning
216for any undeclared partial function.
216for any undeclared partial function.
217
217
218Totality checking issues
218Totality checking issues
219−~~~~~~~~~~~~~~~~~~~~~~~~
219+------------------------
220
220
221Please note that the totality checker is not perfect! Firstly, it is
221Please note that the totality checker is not perfect! Firstly, it is
222necessarily conservative due to the undecidability of the halting
222necessarily conservative due to the undecidability of the halting
@@ -226,14 +226,14 @@ into it so far, so there may still be cases where it believes a function
226is total which is not. Do not rely on it for your proofs yet!
226is total which is not. Do not rely on it for your proofs yet!
227
227
228Hints for totality
228Hints for totality
229−~~~~~~~~~~~~~~~~~~
229+------------------
230
230
231In cases where you believe a program is total, but Idris does not agree, it is
231In cases where you believe a program is total, but Idris does not agree, it is
232possible to give hints to the checker to give more detail for a termination
232possible to give hints to the checker to give more detail for a termination
233argument. The checker works by ensuring that all chains of recursive calls
233argument. The checker works by ensuring that all chains of recursive calls
234eventually lead to one of the arguments decreasing towards a base case, but
234eventually lead to one of the arguments decreasing towards a base case, but
235sometimes this is hard to spot. For example, the following definition cannot be
235sometimes this is hard to spot. For example, the following definition cannot be
236−checked as ``total`` because the checker cannot decide that ``filter (<= x) xs``
236+checked as ``total`` because the checker cannot decide that ``filter (<= x) xs``
237will always be smaller than ``(x :: xs)``:
237will always be smaller than ``(x :: xs)``:
238
238
239.. code-block:: idris
239.. code-block:: idris
docs/tutorial/typesfuns.rst+29−29
@@ -1,11 +1,11 @@
1.. _sect-typefuns:
1.. _sect-typefuns:
2
2
3−===================
3+*******************
4Types and Functions
4Types and Functions
5−===================
5+*******************
6
6
7Primitive Types
7Primitive Types
8−---------------
8+===============
9
9
10Idris defines several primitive types: ``Int``, ``Integer`` and
10Idris defines several primitive types: ``Int``, ``Integer`` and
11``Float`` for numeric operations, ``Char`` and ``String`` for text
11``Float`` for numeric operations, ``Char`` and ``String`` for text
@@ -71,7 +71,7 @@ work on user defined types. Boolean expressions can be tested with the
71 "The answer!" : String
71 "The answer!" : String
72
72
73Data Types
73Data Types
74−----------
74+==========
75
75
76Data types are declared in a similar way to Haskell data types, with a
76Data types are declared in a similar way to Haskell data types, with a
77similar syntax. Natural numbers and lists, for example, can be
77similar syntax. Natural numbers and lists, for example, can be
@@ -105,7 +105,7 @@ symbols:
105 :+-*/=_.?|&><!@$%^~.
105 :+-*/=_.?|&><!@$%^~.
106
106
107Functions
107Functions
108−---------
108+=========
109
109
110Functions are implemented by pattern matching, again using a similar
110Functions are implemented by pattern matching, again using a similar
111syntax to Haskell. The main difference is that Idris requires type
111syntax to Haskell. The main difference is that Idris requires type
@@ -175,7 +175,7 @@ numbers. This means it can optimise the representation, and functions
175such as ``plus`` and ``mult``.
175such as ``plus`` and ``mult``.
176
176
177``where`` clauses
177``where`` clauses
178−~~~~~~~~~~~~~~~~~
178+-----------------
179
179
180Functions can also be defined *locally* using ``where`` clauses. For
180Functions can also be defined *locally* using ``where`` clauses. For
181example, to define a function which reverses a list, we can use an
181example, to define a function which reverses a list, we can use an
@@ -241,10 +241,10 @@ So, for example, the following definitions are legal:
241 where z w = y + w
241 where z w = y + w
242
242
243Dependent Types
243Dependent Types
244−---------------
244+===============
245
245
246Vectors
246Vectors
247−~~~~~~~
247+-------
248
248
249A standard example of a dependent type is the type of “lists with
249A standard example of a dependent type is the type of “lists with
250length”, conventionally called vectors in the dependent type
250length”, conventionally called vectors in the dependent type
@@ -322,7 +322,7 @@ two vectors — we needed a vector of length ``k + m``, but provided a
322vector of length ``k + k``.
322vector of length ``k + k``.
323
323
324The Finite Sets
324The Finite Sets
325−~~~~~~~~~~~~~~~
325+---------------
326
326
327Finite sets, as the name suggests, are sets with a finite number of
327Finite sets, as the name suggests, are sets with a finite number of
328elements. They are available as part of the Idris library, by
328elements. They are available as part of the Idris library, by
@@ -337,12 +337,12 @@ importing ``Data.Fin``, or can be declared as follows:
337From the signature, we can see that this is a type constructor that takes a ``Nat``, and produces a type.
337From the signature, we can see that this is a type constructor that takes a ``Nat``, and produces a type.
338So this is not a set in the sense of a collection that is a container of objects,
338So this is not a set in the sense of a collection that is a container of objects,
339rather it is the canonical set of unnamed elements, as in "the set of 5 elements," for example.
339rather it is the canonical set of unnamed elements, as in "the set of 5 elements," for example.
340−Effectively, it is a type that captures integers that fall into the range of zero to ``(n - 1)`` where
340+Effectively, it is a type that captures integers that fall into the range of zero to ``(n - 1)`` where
341``n`` is the argument used to instantiate the ``Fin`` type.
341``n`` is the argument used to instantiate the ``Fin`` type.
342For example, ``Fin 5`` can be thought of as the type of integers between 0 and 4.
342For example, ``Fin 5`` can be thought of as the type of integers between 0 and 4.
343
343
344Let us look at the constructors in greater detail.
344Let us look at the constructors in greater detail.
345−
345+
346``FZ`` is the zeroth element of a finite set with ``S k`` elements;
346``FZ`` is the zeroth element of a finite set with ``S k`` elements;
347``FS n`` is the ``n+1``\ th element of a finite set with ``S k``
347``FS n`` is the ``n+1``\ th element of a finite set with ``S k``
348elements. ``Fin`` is indexed by a ``Nat``, which represents the number
348elements. ``Fin`` is indexed by a ``Nat``, which represents the number
@@ -377,7 +377,7 @@ attempting to look up an element in an empty vector would give a
377compile time type error, since it would force ``n`` to be ``Z``.
377compile time type error, since it would force ``n`` to be ``Z``.
378
378
379Implicit Arguments
379Implicit Arguments
380−~~~~~~~~~~~~~~~~~~
380+------------------
381
381
382Let us take a closer look at the type of ``index``:
382Let us take a closer look at the type of ``index``:
383
383
@@ -420,7 +420,7 @@ help document a function by making the purpose of an argument more
420clear.
420clear.
421
421
422“``using``” notation
422“``using``” notation
423−~~~~~~~~~~~~~~~~~~~~
423+--------------------
424
424
425Sometimes it is useful to provide types of implicit arguments,
425Sometimes it is useful to provide types of implicit arguments,
426particularly where there is a dependency ordering, or where the
426particularly where there is a dependency ordering, or where the
@@ -460,7 +460,7 @@ appear within the block:
460 There : Elem x xs -> Elem x (y :: xs)
460 There : Elem x xs -> Elem x (y :: xs)
461
461
462Note: Declaration Order and ``mutual`` blocks
462Note: Declaration Order and ``mutual`` blocks
463−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
463+---------------------------------------------
464
464
465In general, functions and data types must be defined before use, since
465In general, functions and data types must be defined before use, since
466dependent types allow functions to appear as part of types, and their
466dependent types allow functions to appear as part of types, and their
@@ -485,7 +485,7 @@ depend on the reduction behaviour of any of the functions in the
485block.
485block.
486
486
487I/O
487I/O
488−---
488+===
489
489
490Computer programs are of little use if they do not interact with the
490Computer programs are of little use if they do not interact with the
491user or the system in some way. The difficulty in a pure language such
491user or the system in some way. The difficulty in a pure language such
@@ -542,7 +542,7 @@ example for reading and writing files, including:
542.. _sect-do:
542.. _sect-do:
543
543
544“``do``” notation
544“``do``” notation
545−-----------------
545+=================
546
546
547I/O programs will typically need to sequence actions, feeding the
547I/O programs will typically need to sequence actions, feeding the
548output of one computation into the input of the next. ``IO`` is an
548output of one computation into the input of the next. ``IO`` is an
@@ -573,7 +573,7 @@ can be overloaded.
573.. _sect-lazy:
573.. _sect-lazy:
574
574
575Laziness
575Laziness
576−--------
576+========
577
577
578Normally, arguments to functions are evaluated before the function
578Normally, arguments to functions are evaluated before the function
579itself (that is, Idris uses *eager* evaluation). However, this is
579itself (that is, Idris uses *eager* evaluation). However, this is
@@ -611,7 +611,7 @@ without any explicit use of ``Force`` or ``Delay``:
611 boolCase False t e = e;
611 boolCase False t e = e;
612
612
613Useful Data Types
613Useful Data Types
614−-----------------
614+=================
615
615
616Idris includes a number of useful data types and library functions
616Idris includes a number of useful data types and library functions
617(see the ``libs/`` directory in the distribution). This chapter
617(see the ``libs/`` directory in the distribution). This chapter
@@ -619,7 +619,7 @@ describes a few of these. The functions described here are imported
619automatically by every Idris program, as part of ``Prelude.idr``.
619automatically by every Idris program, as part of ``Prelude.idr``.
620
620
621``List`` and ``Vect``
621``List`` and ``Vect``
622−~~~~~~~~~~~~~~~~~~~~~
622+---------------------
623
623
624We have already seen the ``List`` and ``Vect`` data types:
624We have already seen the ``List`` and ``Vect`` data types:
625
625
@@ -692,7 +692,7 @@ remember that Idris is still in development, so if you don’t see
692the function you need, please feel free to add it and submit a patch!
692the function you need, please feel free to add it and submit a patch!
693
693
694Aside: Anonymous functions and operator sections
694Aside: Anonymous functions and operator sections
695−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
695+------------------------------------------------
696
696
697There are actually neater ways to write the above expression. One way
697There are actually neater ways to write the above expression. One way
698would be to use an anonymous function:
698would be to use an anonymous function:
@@ -719,7 +719,7 @@ by 2. It expands to ``\x => x * 2``. Similarly, ``(2*)`` would expand
719to ``\x => 2 * x``.
719to ``\x => 2 * x``.
720
720
721Maybe
721Maybe
722−~~~~~
722+-----
723
723
724``Maybe`` describes an optional value. Either there is a value of the
724``Maybe`` describes an optional value. Either there is a value of the
725given type, or there isn’t:
725given type, or there isn’t:
@@ -753,7 +753,7 @@ simply ``b``. Since the default value might not be used, we mark it as
753discarding it would be wasteful.
753discarding it would be wasteful.
754
754
755Tuples and Dependent Pairs
755Tuples and Dependent Pairs
756−~~~~~~~~~~~~~~~~~~~~~~~~~~
756+--------------------------
757
757
758Values can be paired with the following built-in data type:
758Values can be paired with the following built-in data type:
759
759
@@ -774,7 +774,7 @@ contain an arbitrary number of values, represented as nested pairs:
774 jim = ("Jim", 25, "Cambridge")
774 jim = ("Jim", 25, "Cambridge")
775
775
776Dependent Pairs
776Dependent Pairs
777−~~~~~~~~~~~~~~~
777+---------------
778
778
779Dependent pairs allow the type of the second element of a pair to depend
779Dependent pairs allow the type of the second element of a pair to depend
780on the value of the first element. Traditionally, these are referred to
780on the value of the first element. Traditionally, these are referred to
@@ -852,10 +852,10 @@ We will see more on ``with`` notation later.
852.. _sect-more-expr:
852.. _sect-more-expr:
853
853
854More Expressions
854More Expressions
855−----------------
855+================
856
856
857``let`` bindings
857``let`` bindings
858−~~~~~~~~~~~~~~~~
858+----------------
859
859
860Intermediate values can be calculated using ``let`` bindings:
860Intermediate values can be calculated using ``let`` bindings:
861
861
@@ -884,7 +884,7 @@ pattern matching at the top level:
884 name ++ " is " ++ show age ++ " years old"
884 name ++ " is " ++ show age ++ " years old"
885
885
886List comprehensions
886List comprehensions
887−~~~~~~~~~~~~~~~~~~~
887+-------------------
888
888
889Idris provides *comprehension* notation as a convenient shorthand
889Idris provides *comprehension* notation as a convenient shorthand
890for building lists. The general form is:
890for building lists. The general form is:
@@ -911,7 +911,7 @@ by the difference between ``a`` and ``b``. This works for any numeric
911type, using the ``count`` function from the prelude.
911type, using the ``count`` function from the prelude.
912
912
913``case`` expressions
913``case`` expressions
914−~~~~~~~~~~~~~~~~~~~~
914+--------------------
915
915
916Another way of inspecting intermediate values of *simple* types is to
916Another way of inspecting intermediate values of *simple* types is to
917use a ``case`` expression. The following function, for example, splits
917use a ``case`` expression. The following function, for example, splits
@@ -965,7 +965,7 @@ matching ``let`` and lambda bindings. It will *only* work if:
965 itself.
965 itself.
966
966
967Dependent Records
967Dependent Records
968−-----------------
968+=================
969
969
970*Records* are data types which collect several values (the record's
970*Records* are data types which collect several values (the record's
971*fields*) together. Idris provides syntax for defining records and
971*fields*) together. Idris provides syntax for defining records and
@@ -1036,7 +1036,7 @@ length because it will not affect the type of the record:
1036 : Class
1036 : Class
1037
1037
1038Nested record update
1038Nested record update
1039−~~~~~~~~~~~~~~~~~~~~
1039+--------------------
1040
1040
1041Idris also provides a convenient syntax for accessing and updating
1041Idris also provides a convenient syntax for accessing and updating
1042nested records. For example, if a field is accessible with the
1042nested records. For example, if a field is accessible with the
docs/tutorial/views.rst+4−4
@@ -1,11 +1,11 @@
1.. _sec-views:
1.. _sec-views:
2
2
3−=============================
3+*****************************
4Views and the “``with``” rule
4Views and the “``with``” rule
5−=============================
5+*****************************
6
6
7Dependent pattern matching
7Dependent pattern matching
8−--------------------------
8+==========================
9
9
10Since types can depend on values, the form of some arguments can be
10Since types can depend on values, the form of some arguments can be
11determined by the value of others. For example, if we were to write
11determined by the value of others. For example, if we were to write
@@ -25,7 +25,7 @@ case, the definition would not be well typed.
25.. _sect-nattobin:
25.. _sect-nattobin:
26
26
27The ``with`` rule — matching intermediate values
27The ``with`` rule — matching intermediate values
28−------------------------------------------------
28+================================================
29
29
30Very often, we need to match on the result of an intermediate
30Very often, we need to match on the result of an intermediate
31computation. Idris provides a construct for this, the ``with``
31computation. Idris provides a construct for this, the ``with``