summaryrefslogtreecommitdiff
path: root/README/Case.agda
diff options
context:
space:
mode:
authorIain Lane <laney@debian.org>2011-11-29 16:51:32 +0000
committerIain Lane <laney@debian.org>2011-11-29 16:51:32 +0000
commitbecce68e992af760dbdc6f17e77bc4dfeecccef7 (patch)
treefe929e2d8863fe17c1c2909283e1442b6f4a3286 /README/Case.agda
parent9251e0b00e309e805a4576ae558b3d1e321d8f2c (diff)
Imported Upstream version 0.6~darcs20111129t1640
Diffstat (limited to 'README/Case.agda')
-rw-r--r--README/Case.agda38
1 files changed, 38 insertions, 0 deletions
diff --git a/README/Case.agda b/README/Case.agda
new file mode 100644
index 0000000..e42f55a
--- /dev/null
+++ b/README/Case.agda
@@ -0,0 +1,38 @@
+------------------------------------------------------------------------
+-- The Agda standard library
+--
+-- Examples showing how the case expressions can be used
+------------------------------------------------------------------------
+
+module README.Case where
+
+open import Data.Fin hiding (pred)
+open import Data.Maybe hiding (from-just)
+open import Data.Nat hiding (pred)
+open import Function
+
+-- Some simple examples.
+
+empty : ∀ {a} {A : Set a} → Fin 0 → A
+empty i = case i of λ()
+
+pred : ℕ → ℕ
+pred n = case n of λ
+ { zero → zero
+ ; (suc n) → n
+ }
+
+from-just : ∀ {a} {A : Set a} (x : Maybe A) → From-just A x
+from-just x = case x return From-just _ of λ
+ { (just x) → x
+ ; nothing → _
+ }
+
+-- Note that some natural uses of case are rejected by the termination
+-- checker:
+--
+-- plus : ℕ → ℕ → ℕ
+-- plus m n = case m of λ
+-- { zero → n
+-- ; (suc m) → suc (plus m n)
+-- }