{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Split where
open import Data.List.Base
as List>
using ([])
renaming (List to List>; _∷_ to _:>_)
open import Data.Product.Base using (_×_; _,_)
open import Data.SnocList.Base
as List<
using (List<; []; _<:_; _<>>_)
open import Level using (Level; _⊔_)
open import Relation.Unary using (Pred)
private
variable
a p : Level
A : Set a
x : A
xs : List> A
sx : List< A
P : Pred A p
infix 1 _||_
data Split {A : Set a} : Pred (List> A) a where
_||_ : (sx : List< A) →
(xs : List> A) →
Split (sx <>> xs)
leftOf : Split {A = A} xs → List< A
leftOf (sx || xs) = sx
rightOf : Split {A = A} xs → List> A
rightOf (sx || xs) = xs
private
variable
spl : Split xs
moveLeft : Split xs → Split xs
moveLeft (sx <: x || xs) = sx || x :> xs
moveLeft sp = sp
moveRight : Split xs → Split xs
moveRight (sx || x :> xs) = sx <: x || xs
moveRight sp = sp
allSplits : (xs : List> A) → List> (Split xs)
allSplits = go [] module AllSplits where
go : (sx : List< A) (xs : List> A) → List> (Split (sx <>> xs))
go sx [] = (sx || []) :> []
go sx (x :> xs) = (sx || x :> xs) :> go (sx <: x) xs
data Allʳ {p} {A : Set a} : ∀ {xs : List> A} →
Pred (Split xs) p →
Pred (Split xs) (a ⊔ Level.suc p)
where
[] : ∀ {P}
→ P (sx || [])
→ Allʳ P (sx || [])
_:>_ : ∀ {P}
→ P (sx || x :> xs)
→ Allʳ P (sx <: x || xs)
→ Allʳ P (sx || x :> xs)
currentʳ : Allʳ P spl → P spl
currentʳ ([] d) = d
currentʳ (d :> _) = d
data Allˡ {p} {A : Set a} : ∀ {xs : List> A} →
Pred (Split xs) p →
Pred (Split xs) (a ⊔ Level.suc p)
where
[] : ∀ {P}
→ P ([] || xs)
→ Allˡ P ([] || xs)
_<:_ : ∀ {P}
→ Allˡ P (sx || x :> xs)
→ P (sx <: x || xs)
→ Allˡ P (sx <: x || xs)
currentˡ : Allˡ P spl → P spl
currentˡ ([] d) = d
currentˡ (_ <: d) = d
All : ∀ {p} {A : Set a} {xs : List> A} →
Pred (Split xs) p →
Pred (Split xs) (a ⊔ Level.suc p)
All P (sx || []) = Allˡ P (sx || [])
All P (sx || x :> xs) = Allˡ P (sx || x :> xs) × Allʳ P (sx <: x || xs)
current : All P spl → P spl
current {spl = _ || []} ps = currentˡ ps
current {spl = _ || _ :> _} (ps , _) = currentˡ ps
stepLeft : All P (sx <: x || xs) → All P (sx || x :> xs)
stepLeft {xs = []} (ls <: d) = ls , [] d
stepLeft {xs = _ :> _} (ls <: d , rs) = ls , d :> rs
stepRight : All P (sx || x :> xs) → All P (sx <: x || xs)
stepRight {xs = []} (ls , rs) = ls <: currentʳ rs
stepRight {xs = _ :> _} (ls , d :> rs) = (ls <: d) , rs