Debian Codegraph @

src/Data/Sum.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Sums (disjoint unions)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Sum where
10
11 open import Data.Unit.Polymorphic.Base using (⊤; tt)
12 open import Data.Maybe.Base using (Maybe; just; nothing)
13 open import Level
14 import Relation.Nullary.Decidable.Core as Dec
15
16 private
17 variable
18 a b : Level
19 A B : Set a
20
21 ------------------------------------------------------------------------
22 -- Re-export content from base module
23
24 open import Data.Sum.Base public
25
26 ------------------------------------------------------------------------
27 -- Additional functions
28
29 module _ {A : Set a} {B : Set b} where
30
31 isInj₁ : A ⊎ B → Maybe A
32 isInj₁ (inj₁ x) = just x
33 isInj₁ (inj₂ y) = nothing
34
35 isInj₂ : A ⊎ B → Maybe B
36 isInj₂ (inj₁ x) = nothing
37 isInj₂ (inj₂ y) = just y
38
39 From-inj₁ : A ⊎ B → Set a
40 From-inj₁ (inj₁ _) = A
41 From-inj₁ (inj₂ _) = ⊤
42
43 from-inj₁ : (x : A ⊎ B) → From-inj₁ x
44 from-inj₁ (inj₁ x) = x
45 from-inj₁ (inj₂ _) = _
46
47 From-inj₂ : A ⊎ B → Set b
48 From-inj₂ (inj₁ _) = ⊤
49 From-inj₂ (inj₂ _) = B
50
51 from-inj₂ : (x : A ⊎ B) → From-inj₂ x
52 from-inj₂ (inj₁ _) = _
53 from-inj₂ (inj₂ x) = x
54
55 ------------------------------------------------------------------------
56 -- DEPRECATED NAMES
57 ------------------------------------------------------------------------
58 -- Please use the new names as continuing support for the old names is
59 -- not guaranteed.
60
61 -- Version 2.1
62
63 open Dec public using (fromDec; toDec)
64