Open
Description
At the moment naming and typing conventions for folds differ quite a lot across the various different data types. As far as I can see there are three basic types of folds present in the standard library (feel free to suggest more if I missed any!):
- Basic folds (applicable to everything
List
,Vec
,Table
etc.)
foldr : ∀ {a b} {A : Set a} {B : Set b} → (A → B → B) → A → ∀ {n} → Vec A n → A
- Dependent folds (applicable to everything)
foldr : ∀ {a b} {A : Set a} (B : ℕ → Set b) {m} →
(∀ {n} → A → B n → B (suc n)) → B zero → Vec A m → B m
- Non-empty folds (applicable to
Vec
,Table
etc)
foldr : ∀ {a} {A : Set a} → (A → A → A) → ∀ {n} → Vec A (suc n) → A
Obviously 1. can be implemented in terms of 2. and 3. can be implemented in terms of 1.
The current state of play is:
Datatype | Name for 1. | Name for 2. | Name for 3. |
---|---|---|---|
List | foldr |
- | N/A |
Vec | - | foldr |
foldr₁ |
Table | foldr |
- | - |
Product.N-ary | - | foldr |
- |
It would be great if we could add in some of the missing ones and come up with some consistent naming scheme for these across all data types for v1.0.
- In my opinion the name
foldr
should always be reserved for this "normal" fold. - I don't have strong opinions or any good suggestions. Maybe something like
dfoldr
orfoldrᵈ
? - I would suggest
foldr₊
to represent the non-emptiness (rather thanfoldr⁺
which would clash for property intoduction proofs).