Debian Codegraph @

doc/README/Effect/Monad/Partiality.agda

raw
1 -----------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Example showing the use of the partiality Monad
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe --guardedness #-}
8
9 module README.Effect.Monad.Partiality where
10
11 open import Codata.Musical.Notation using (♯_)
12 open import Data.Bool.Base using (false; true)
13 open import Data.Nat using (ℕ; _+_; _∸_; _≤?_)
14 open import Effect.Monad.Partiality
15 open import Relation.Nullary.Decidable using (does)
16
17 open Workaround
18
19 -- McCarthy's f91:
20
21 f91′ : ℕ → ℕ ⊥P
22 f91′ n with does (n ≤? 100)
23 ... | true = later (♯ (f91′ (11 + n) >>= f91′))
24 ... | false = now (n ∸ 10)
25
26 f91 : ℕ → ℕ ⊥
27 f91 n = ⟦ f91′ n ⟧P