Skip to content

Commit 0e3577e

Browse files
authored
[ new ] postulate length-tail lemma (#1366)
1 parent cd0f00a commit 0e3577e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,15 @@ Other minor additions
288288
```
289289

290290
* Added infix declarations to `Data.Product.∃-syntax` and `Data.Product.∄-syntax`.
291+
292+
* Added new functions to `Data.String.Base`:
293+
```
294+
uncons : String → Maybe (Char × String)
295+
head : String → Maybe Char
296+
tail : String → Maybe String
297+
```
298+
299+
* Added new property to `Data.String.Unsafe`:
300+
```agda
301+
length-tail : length s ≡ maybe′ (suc ∘′ length) zero (tail s)
302+
```

src/Data/String/Base.agda

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ module Data.String.Base where
1111
open import Level using (zero)
1212
open import Data.Bool.Base using (true; false)
1313
open import Data.Bool.Properties using (T?)
14+
open import Data.Maybe.Base as Maybe using (Maybe)
1415
open import Data.Nat.Base as ℕ using (ℕ; _∸_; ⌊_/2⌋; ⌈_/2⌉; _⊔_)
16+
open import Data.Product using (proj₁; proj₂)
1517
open import Data.List.Base as List using (List; [_])
1618
open import Data.List.NonEmpty as NE using (List⁺)
1719
open import Data.List.Relation.Binary.Pointwise using (Pointwise)
@@ -60,6 +62,14 @@ _<_ = Lex-< Char._≈_ Char._<_ on toList
6062
------------------------------------------------------------------------
6163
-- Operations
6264

65+
-- List-like operations
66+
67+
head : String Maybe Char
68+
head = Maybe.map proj₁ ∘′ uncons
69+
70+
tail : String Maybe String
71+
tail = Maybe.map proj₂ ∘′ uncons
72+
6373
-- Additional conversion functions
6474

6575
fromChar : Char String

src/Data/String/Unsafe.agda

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ module Data.String.Unsafe where
1010

1111
import Data.List.Base as List
1212
import Data.List.Properties as Listₚ
13-
open import Data.Nat.Base using (_+_)
13+
open import Data.Maybe.Base using (maybe′)
14+
open import Data.Nat.Base using (zero; suc; _+_)
15+
open import Data.Product using (proj₂)
1416
open import Data.String.Base
17+
open import Function.Base using (_∘′_)
1518

1619
open import Relation.Binary.PropositionalEquality; open ≡-Reasoning
1720
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
1821

22+
------------------------------------------------------------------------
23+
-- Properties of tail
24+
25+
length-tail : s length s ≡ maybe′ (suc ∘′ length) zero (tail s)
26+
length-tail s = trustMe
27+
1928
------------------------------------------------------------------------
2029
-- Properties of conversion functions
2130

0 commit comments

Comments
 (0)