@@ -232,7 +232,7 @@ Using this we can, for example, define a function which adds two
232 m_add : Maybe Int -> Maybe Int -> Maybe Int
232 m_add : Maybe Int -> Maybe Int -> Maybe Int
233 m_add x y = do x' <- x -- Extract value from x
233 m_add x y = do x' <- x -- Extract value from x
234 y' <- y -- Extract value from y
234 y' <- y -- Extract value from y
235− return (x' + y') -- Add them
235+ pure (x' + y') -- Add them
237This function will extract the values from ``x`` and ``y``, if they
237This function will extract the values from ``x`` and ``y``, if they
238are both available, or return ``Nothing`` if one or both are not ("fail fast"). Managing the
238are both available, or return ``Nothing`` if one or both are not ("fail fast"). Managing the
@@ -270,7 +270,7 @@ on the result of ``readNumber``:
270.. code-block:: idris
270.. code-block:: idris
272 readNumbers : IO (Maybe (Nat, Nat))
272 readNumbers : IO (Maybe (Nat, Nat))
273− readNumbers =
273+ readNumbers =
274 do x <- readNumber
274 do x <- readNumber
275 case x of
275 case x of
276 Nothing => pure Nothing
276 Nothing => pure Nothing
@@ -286,7 +286,7 @@ we could try pattern matching on values of the form ``Just x_ok``:
286.. code-block:: idris
286.. code-block:: idris
288 readNumbers : IO (Maybe (Nat, Nat))
288 readNumbers : IO (Maybe (Nat, Nat))
289− readNumbers =
289+ readNumbers =
290 do Just x_ok <- readNumber
290 do Just x_ok <- readNumber
291 Just y_ok <- readNumber
291 Just y_ok <- readNumber
292 pure (Just (x_ok, y_ok))
292 pure (Just (x_ok, y_ok))
@@ -298,7 +298,7 @@ case back as follows:
298.. code-block:: idris
298.. code-block:: idris
300 readNumbers : IO (Maybe (Nat, Nat))
300 readNumbers : IO (Maybe (Nat, Nat))
301− readNumbers =
301+ readNumbers =
302 do Just x_ok <- readNumber | Nothing => pure Nothing
302 do Just x_ok <- readNumber | Nothing => pure Nothing
303 Just y_ok <- readNumber | Nothing => pure Nothing
303 Just y_ok <- readNumber | Nothing => pure Nothing
304 pure (Just (x_ok, y_ok))
304 pure (Just (x_ok, y_ok))
@@ -321,7 +321,7 @@ shorthand version, as follows:
321.. code-block:: idris
321.. code-block:: idris
323 m_add : Maybe Int -> Maybe Int -> Maybe Int
323 m_add : Maybe Int -> Maybe Int -> Maybe Int
324− m_add x y = return (!x + !y)
324+ m_add x y = pure (!x + !y)
326The notation ``!expr`` means that the expression ``expr`` should be
326The notation ``!expr`` means that the expression ``expr`` should be
327evaluated and then implicitly bound. Conceptually, we can think of
327evaluated and then implicitly bound. Conceptually, we can think of
@@ -388,7 +388,7 @@ Then the comprehension is converted to ``do`` notation:
389.. code-block:: idris
389.. code-block:: idris
391− do { qual1; qual2; ...; qualn; return exp; }
391+ do { qual1; qual2; ...; qualn; pure exp; }
393Using monad comprehensions, an alternative definition for ``m_add``
393Using monad comprehensions, an alternative definition for ``m_add``