@@ -156,12 +156,10 @@ new effects, however.
159−Listing :ref:`eff-statedef` summarises what is required to define the
159+The following listing summarises what is required to define the
160−``STATE`` effect.
160+``STATE`` effect:
163.. code-block:: idris
162.. code-block:: idris
164− :caption: Complete State Effect Definition
166 data State : Effect where
164 data State : Effect where
167 Get : { a } State a
165 Get : { a } State a
@@ -187,7 +185,7 @@ Listing :ref:`eff-statedef` summarises what is required to define the
187Console I/O
185Console I/O
188-----------
186-----------
190−Listing :ref:`eff-stdiodef` gives the definition of the ``STDIO``
188+Then listing below gives the definition of the ``STDIO``
191effect, including handlers for ``IO`` and ``IOExcept``. We omit the
189effect, including handlers for ``IO`` and ``IOExcept``. We omit the
192definition of the top level ``Eff`` functions, as this merely invoke
190definition of the top level ``Eff`` functions, as this merely invoke
193the effects ``PutStr``, ``GetStr``, ``PutCh`` and ``GetCh`` directly.
191the effects ``PutStr``, ``GetStr``, ``PutCh`` and ``GetCh`` directly.
@@ -198,7 +196,6 @@ directly.
199.. _eff-stdiodef:
197.. _eff-stdiodef:
200.. code-block:: idris
198.. code-block:: idris
201− :caption: Console I/O Effect Definition
203 data StdIO : Effect where
200 data StdIO : Effect where
204 PutStr : String -> { () } StdIO ()
201 PutStr : String -> { () } StdIO ()
@@ -224,9 +221,14 @@ directly.
224Exceptions
221Exceptions
225----------
222----------
227−.. _eff-exceptdef:
224+The listing below gives the definition of the ``Exception``
225+effect, including two of its handlers for ``Maybe`` and ``List``. The
226+only operation provided is ``Raise``. The key point to note in the
227+definitions of these handlers is that the continuation ``k`` is not
228+used. Running ``Raise`` therefore means that computation stops with an
228.. code-block:: idris
231.. code-block:: idris
229− :caption: Exception Effect Definition
231 data Exception : Type -> Effect where
233 data Exception : Type -> Effect where
232 Raise : a -> { () } Exception a b
234 Raise : a -> { () } Exception a b
@@ -240,19 +242,17 @@ Exceptions
240 EXCEPTION : Type -> EFFECT
242 EXCEPTION : Type -> EFFECT
241 EXCEPTION t = MkEff () (Exception t)
243 EXCEPTION t = MkEff () (Exception t)
243−Listing :ref:`eff-exceptdef` gives the definition of the ``Exception``
244−effect, including two of its handlers for ``Maybe`` and ``List``. The
245−only operation provided is ``Raise``. The key point to note in the
246−definitions of these handlers is that the continuation ``k`` is not
247−used. Running ``Raise`` therefore means that computation stops with an
250Non-determinism
246Non-determinism
251---------------
247---------------
253−.. _eff-selectdef:
249+The following listing gives the definition of the ``Select``
250+effect for writing non-deterministic programs, including a handler for
251+``List`` context which returns all possible successful values, and a
252+handler for ``Maybe`` context which returns the first successful
254.. code-block:: idris
255.. code-block:: idris
255− :caption: Non-determinism Effect Definition
257 data Selection : Effect where
257 data Selection : Effect where
258 Select : List a -> { () } Selection a
258 Select : List a -> { () } Selection a
@@ -270,11 +270,6 @@ Non-determinism
270 SELECT : EFFECT
270 SELECT : EFFECT
271 SELECT = MkEff () Selection
271 SELECT = MkEff () Selection
273−Listing :ref:`eff-selectdef` gives the definition of the ``Select``
274−effect for writing non-deterministic programs, including a handler for
275−``List`` context which returns all possible successful values, and a
276−handler for ``Maybe`` context which returns the first successful
279Here, the continuation is called multiple times in each handler, for
274Here, the continuation is called multiple times in each handler, for
280each value in the list of possible values. In the ``List`` handler, we
275each value in the list of possible values. In the ``List`` handler, we
@@ -285,21 +280,13 @@ File Management
285---------------
280---------------
287Result-dependent effects are no different from non-dependent effects
282Result-dependent effects are no different from non-dependent effects
288−in the way they are implemented. Listing :ref:`eff-filedef`
283+in the way they are implemented. The listing below
289illustrates this for the ``FILE_IO`` effect. The syntax for state
284illustrates this for the ``FILE_IO`` effect. The syntax for state
290transitions ``{ x ==> {res} x’ }``, where the result state ``x’`` is
285transitions ``{ x ==> {res} x’ }``, where the result state ``x’`` is
291computed from the result of the operation ``res``, follows that for
286computed from the result of the operation ``res``, follows that for
292the equivalent ``Eff`` programs.
287the equivalent ``Eff`` programs.
294−Note that in the handler for ``Open``, the types passed to the
295−continuation ``k`` are different depending on whether the result is
296−``True`` (opening succeeded) or ``False`` (opening failed). This uses
297−``validFile``, defined in the ``Prelude``, to test whether a file
298−handler refers to an open file or not.
301.. code-block:: idris
289.. code-block:: idris
302− :caption: File I/O Effect Definition
304 data FileIO : Effect where
291 data FileIO : Effect where
305 Open : String -> (m : Mode) ->
292 Open : String -> (m : Mode) ->
@@ -327,3 +314,10 @@ handler refers to an open file or not.
328 FILE_IO : Type -> EFFECT
315 FILE_IO : Type -> EFFECT
329 FILE_IO t = MkEff t FileIO
316 FILE_IO t = MkEff t FileIO
318+Note that in the handler for ``Open``, the types passed to the
319+continuation ``k`` are different depending on whether the result is
320+``True`` (opening succeeded) or ``False`` (opening failed). This uses
321+``validFile``, defined in the ``Prelude``, to test whether a file
322+handler refers to an open file or not.