Debian Codegraph @

src/Data/List/Kleene/AsList.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- A different interface to the Kleene lists, designed to mimic
5 -- Data.List.
6 ------------------------------------------------------------------------
7
8 {-# OPTIONS --cubical-compatible --safe #-}
9
10 module Data.List.Kleene.AsList where
11
12 open import Level as Level using (Level)
13
14 private
15 variable
16 a b c : Level
17 A : Set a
18 B : Set b
19 C : Set c
20
21 import Data.List.Kleene.Base as Kleene using ([])
22
23 ------------------------------------------------------------------------
24 -- Here we import half of the functions from Data.KleeneList: the half
25 -- for possibly-empty lists.
26
27 open import Data.List.Kleene.Base public
28 using ([])
29 renaming
30 ( _* to List
31 ; foldr* to foldr
32 ; foldl* to foldl
33 ; _++*_ to _++_
34 ; map* to map
35 ; mapMaybe* to mapMaybe
36 ; pure* to pure
37 ; _<*>*_ to _<*>_
38 ; _>>=*_ to _>>=_
39 ; mapAccumˡ* to mapAccumˡ
40 ; mapAccumʳ* to mapAccumʳ
41 ; _[_]* to _[_]
42 ; applyUpTo* to applyUpTo
43 ; upTo* to upTo
44 ; zipWith* to zipWith
45 ; unzipWith* to unzipWith
46 ; partitionSumsWith* to partitionSumsWith
47 ; reverse* to reverse
48 )
49
50 ------------------------------------------------------------------------
51 -- A pattern which mimics Data.List._∷_
52
53 infixr 5 _∷_
54 pattern _∷_ x xs = Kleene.∹ x Kleene.& xs
55
56 ------------------------------------------------------------------------
57 -- The following functions change the type of the list (from ⁺ to * or
58 -- vice versa) in Data.KleeneList, so we reimplement them here to keep
59 -- the type the same.
60
61 scanr : (A → B → B) → B → List A → List B
62 scanr f b xs = Kleene.∹ Kleene.scanr* f b xs
63
64 scanl : (B → A → B) → B → List A → List B
65 scanl f b xs = Kleene.∹ Kleene.scanl* f b xs
66
67 tails : List A → List (List A)
68 tails xs = foldr (λ x xs → (Kleene.∹ x) ∷ xs) ([] ∷ []) (Kleene.tails* xs)