[ doc ] Update documentation for with

This commit is contained in:
Steve Dunham 2024-05-11 14:11:01 -07:00 committed by G. Allais
parent 004f1fd26b
commit c0ac024114
2 changed files with 16 additions and 5 deletions

View File

@ -4,10 +4,6 @@
Views and the “``with``” rule
*****************************
.. warning::
NOT UPDATED FOR IDRIS 2 YET
Dependent pattern matching
==========================
@ -39,6 +35,11 @@ affect what we know about the forms of other values. In its simplest
form, the ``with`` rule adds another argument to the function being
defined.
When this intermediate computation additionally appears in the type of the
function being defined, the ``with`` construct allows us to capture these
occurrences so that the observations made in the patterns will be reflected
in the type.
We have already seen a vector filter function. This time, we define it
using ``with`` as follows:
@ -86,6 +87,16 @@ that the above ``foo`` can be rewritten as follows:
_ | _ = False
_ | _ = False
Equivalently, multiple expressions separated by ``|`` can be can be deconstructed in one
``with`` statement:
.. code-block:: idris
foo : Int -> Int -> Bool
foo n m with (n + 1) | (m + 1)
_ | 2 | 3 = True
_ | _ | _ = False
If the intermediate computation itself has a dependent type, then the
result can affect the forms of other arguments — we can learn the form
of one value by testing another. In these cases, view refined argument

View File

@ -532,7 +532,7 @@ withabstraction = vcat $
We often need to match on the result of an intermediate computation.
When this intermediate computation additionally appears in the type of the
function being defined, the `with` construct allows us to capture these
occurences so that the observations made in the patterns will be reflected
occurrences so that the observations made in the patterns will be reflected
in the type.
If we additionally need to remember that the link between the patterns and
the intermediate computation we can use the `proof` keyword to retain an