Debian Codegraph @

src/Data/Star/List.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Lists defined in terms of the reflexive-transitive closure, Star
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Star.List where
10
11 open import Data.Star.Nat using (ℕ; _+_; zero)
12 open import Data.Unit.Base using (tt)
13 open import Relation.Binary.Construct.Always using (Always)
14 open import Relation.Binary.Construct.Constant using (Const)
15 open import Relation.Binary.Construct.Closure.ReflexiveTransitive
16 using (Star; ε; _◅_; fold)
17
18 -- Lists.
19
20 List : ∀ {a} → Set a → Set a
21 List A = Star (Const A) tt tt
22
23 -- Nil and cons.
24
25 [] : ∀ {a} {A : Set a} → List A
26 [] = ε
27
28 infixr 5 _∷_
29
30 _∷_ : ∀ {a} {A : Set a} → A → List A → List A
31 _∷_ = _◅_
32
33 -- The sum of the elements in a list containing natural numbers.
34
35 sum : List ℕ → ℕ
36 sum = fold (Star Always) _+_ zero