-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d4b20d
commit 3650866
Showing
5 changed files
with
325 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{-# OPTIONS --safe --cubical-compatible #-} | ||
|
||
-- Working with snoc lists. | ||
module Data.List.Snoc where | ||
open import Data.Product | ||
open import Relation.Nullary | ||
|
||
private variable | ||
X : Set | ||
|
||
data List (X : Set) : Set where | ||
[] : List X | ||
_,-_ : X → List X → List X | ||
|
||
data Empty {X : Set} : List X → Set where | ||
instance [] : Empty [] | ||
|
||
data NonEmpty {X : Set} : List X → Set where | ||
instance cons : ∀ {x xs} → NonEmpty (x ,- xs) | ||
|
||
¬Empty&NonEmpty : ∀ {X} {xs : List X} → ¬ (Empty xs × NonEmpty xs) | ||
¬Empty&NonEmpty ([] , ()) | ||
|
||
data Tsil (X : Set) : Set where | ||
[] : Tsil X | ||
_-,_ : Tsil X → X → Tsil X | ||
|
||
head : (xs : List X) → {{_ : NonEmpty xs}} → X | ||
head (x ,- xs) = x | ||
|
||
_><<_ : Tsil X → List X → List X | ||
[] ><< ys = ys | ||
(sx -, x) ><< ys = sx ><< (x ,- ys) | ||
|
||
_><>_ : Tsil X → List X → Tsil X | ||
sx ><> [] = sx | ||
sx ><> (x ,- xs) = (sx -, x) ><> xs | ||
|
||
record Zipper (X : Set) : Set where | ||
constructor _,_ | ||
field | ||
front : Tsil X | ||
back : List X | ||
open Zipper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
{-# OPTIONS --safe --cubical-compatible #-} | ||
|
||
-- Working with snoc lists. | ||
module Data.Vec.Snoc where | ||
open import Data.Product | ||
open import Data.Nat | ||
open import Data.Nat.Properties | ||
open import Data.List.Snoc using (List; Tsil; []; _,-_; _-,_) | ||
open import Relation.Nullary | ||
open import Relation.Binary.PropositionalEquality | ||
|
||
private variable | ||
X : Set | ||
|
||
data Vec (X : Set) : ℕ → Set where | ||
[] : Vec X 0 | ||
_,-_ : ∀ {n} → X → Vec X n → Vec X (suc n) | ||
|
||
data Cev (X : Set) : ℕ → Set where | ||
[] : Cev X 0 | ||
_-,_ : ∀ {n} → Cev X n → X → Cev X (suc n) | ||
|
||
head : ∀ {n} → (xs : Vec X n) {{_ : NonZero n}} → X | ||
head (x ,- xs) = x | ||
|
||
_><<_ : ∀ {n m} → Cev X n → Vec X m → Vec X (n + m) | ||
[] ><< ys = ys | ||
_><<_ {n = suc n} {m} (sx -, x) ys rewrite sym (+-suc n m) = sx ><< (x ,- ys) | ||
|
||
_><>_ : ∀ {n m} → Cev X n → Vec X m → Cev X (n + m) | ||
_><>_ {n = n} sx [] rewrite +-identityʳ n = sx | ||
_><>_ {n = n} {suc m} sx (x ,- xs) rewrite (+-suc n m) = (sx -, x) ><> xs | ||
|
||
_<<<_ : ∀ {n m} → Vec X n → Vec X m → Vec X (n + m) | ||
_<<<_ [] ys = ys | ||
_<<<_ (x ,- xs) ys = x ,- (xs <<< ys) | ||
|
||
repeat : ∀ {n} → (k : ℕ) → Vec X n → Vec X (k * n) | ||
repeat zero xs = [] | ||
repeat (suc k) xs = xs <<< repeat k xs | ||
|
||
-- record Zipper (X : Set) : Set where | ||
-- constructor _,_ | ||
-- field | ||
-- front : Tsil X | ||
-- back : List X | ||
-- open Zipper |
Oops, something went wrong.