Skip to content

Commit

Permalink
Update TypeDD Chapter 11 for idris2
Browse files Browse the repository at this point in the history
There is a difference between idris1 and idris2 which breaks backwards compatibility when trying to implement `(>>=)` to use `do` notation for a custom type. See idris-lang#1095 for details.
  • Loading branch information
trevarj authored Jan 30, 2022
1 parent 44245e1 commit 6fa9b77
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/source/typedd/typedd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ also have to be ``export``. Also, update ``randoms`` and ``import Data.Bits`` as

In ``StreamFail.idr``, add a ``partial`` annotation to ``labelWith``.

When implementing ``(>>=)`` to support ``do`` notation for custom types, like ``RunIO``, you must now add an extra data constructor ``(>>)`` to help desugaring. See this `test <https://github.com/edwinb/Idris2/tree/master/tests/typedd-book/chapter11/RunIO.idr>`_ or this `pull request <https://github.com/idris-lang/Idris2/pull/1095#issue-812492593>`_ for more details.

.. code-block:: idris
data RunIO : Type -> Type where
Quit : a -> RunIO a
Do : IO a -> (a -> Inf (RunIO b)) -> RunIO b
Seq : IO () -> Inf (RunIO b) -> RunIO b
(>>=) : IO a -> (a -> Inf (RunIO b)) -> RunIO b
(>>=) = Do
(>>) : IO () -> Inf (RunIO b) -> RunIO b
(>>) = Seq
Chapter 12
----------

Expand Down

0 comments on commit 6fa9b77

Please sign in to comment.