Skip to content

Commit d21c942

Browse files
committed
refactor: Bool analogue of agda#2558
1 parent 908e015 commit d21c942

File tree

3 files changed

+80
-19
lines changed

3 files changed

+80
-19
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ Deprecated modules
2121
Deprecated names
2222
----------------
2323

24+
* In `Data.List.Base`:
25+
```agda
26+
and ↦ Data.Bool.ListAction.and
27+
or ↦ Data.Bool.ListAction.or
28+
any ↦ Data.Bool.ListAction.any
29+
all ↦ Data.Bool.ListAction.all
30+
```
31+
2432
New modules
2533
-----------
2634

35+
* `Data.List.Base.{and|or|any|all}` and their properties have been lifted out into `Data.Bool.ListAction`.
36+
2737
Additions to existing modules
2838
-----------------------------
2939

src/Data/Bool/ListAction.agda

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Natural numbers: sum and product of lists
5+
--
6+
-- Issue #2553: this is a compatibility stub module,
7+
-- ahead of a more thorough breaking set of changes.
8+
------------------------------------------------------------------------
9+
10+
{-# OPTIONS --cubical-compatible --safe #-}
11+
12+
module Data.Bool.ListAction where
13+
14+
open import Data.Bool.Base using (Bool; _∧_; _∨_; true; false)
15+
open import Data.List.Base using (List; map; foldr)
16+
open import Function.Base using (_∘_)
17+
open import Level
18+
19+
private
20+
variable
21+
a : Level
22+
A : Set a
23+
24+
25+
------------------------------------------------------------------------
26+
-- Definitions
27+
28+
and : List Bool Bool
29+
and = foldr _∧_ true
30+
31+
or : List Bool Bool
32+
or = foldr _∨_ false
33+
34+
any : (A Bool) List A Bool
35+
any p = or ∘ map p
36+
37+
all : (A Bool) List A Bool
38+
all p = and ∘ map p
39+

src/Data/List/Base.agda

+31-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open import Data.Bool.Base as Bool
1616
using (Bool; false; true; not; _∧_; _∨_; if_then_else_)
1717
open import Data.Fin.Base using (Fin; zero; suc)
1818
open import Data.Maybe.Base as Maybe using (Maybe; nothing; just; maybe′)
19-
open import Data.Nat.Base as ℕ using (ℕ; zero; suc; _+_; _*_ ; _≤_ ; s≤s)
19+
open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
2020
open import Data.Product.Base as Product using (_×_; _,_; map₁; map₂′)
2121
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
2222
open import Data.These.Base as These using (These; this; that; these)
@@ -150,24 +150,6 @@ null : List A → Bool
150150
null [] = true
151151
null (x ∷ xs) = false
152152

153-
and : List Bool Bool
154-
and = foldr _∧_ true
155-
156-
or : List Bool Bool
157-
or = foldr _∨_ false
158-
159-
any : (A Bool) List A Bool
160-
any p = or ∘ map p
161-
162-
all : (A Bool) List A Bool
163-
all p = and ∘ map p
164-
165-
sum : List ℕ
166-
sum = foldr _+_ 0
167-
168-
product : List ℕ
169-
product = foldr _*_ 1
170-
171153
length : List A
172154
length = foldr (const suc) 0
173155

@@ -580,3 +562,33 @@ scanl f e (x ∷ xs) = e ∷ scanl f (f e x) xs
580562
"Warning: scanl was deprecated in v2.1.
581563
Please use Data.List.Scans.Base.scanl instead."
582564
#-}
565+
566+
-- Version 2.3
567+
568+
and : List Bool Bool
569+
and = foldr _∧_ true
570+
571+
all : (A Bool) List A Bool
572+
all p = and ∘ map p
573+
{-# WARNING_ON_USAGE and
574+
"Warning: and was deprecated in v2.3.
575+
Please use Data.Bool.ListAction.and instead."
576+
#-}
577+
{-# WARNING_ON_USAGE all
578+
"Warning: all was deprecated in v2.3.
579+
Please use Data.Nat.ListAction.all instead."
580+
#-}
581+
582+
or : List Bool Bool
583+
or = foldr _∨_ false
584+
585+
any : (A Bool) List A Bool
586+
any p = or ∘ map p
587+
{-# WARNING_ON_USAGE or
588+
"Warning: or was deprecated in v2.3.
589+
Please use Data.Bool.ListAction.or instead."
590+
#-}
591+
{-# WARNING_ON_USAGE any
592+
"Warning: any was deprecated in v2.3.
593+
Please use Data.Bool.ListAction.any instead."
594+
#-}

0 commit comments

Comments
 (0)