quox/lib/Quox/OPE/Length.idr

40 lines
863 B
Idris
Raw Permalink Normal View History

2022-11-06 06:39:33 -05:00
module Quox.OPE.Length
import Quox.OPE.Basics
%default total
public export
data Length : Scope a -> Type where
Z : Length [<]
S : (s : Length xs) -> Length (xs :< x)
%name Length s
%builtin Natural Length
public export
(.nat) : Length xs -> Nat
(Z).nat = Z
(S s).nat = S s.nat
%transform "Length.nat" Length.(.nat) xs = believe_me xs
export
0 ok : (s : Length xs) -> s.nat = length xs
ok Z = Refl
ok (S s) = cong S $ ok s
public export %hint
toLength : (xs : Scope a) -> Length xs
toLength [<] = Z
toLength (sx :< x) = S (toLength sx)
2022-11-15 09:44:49 -05:00
public export %hint
lengthApp : Length xs -> Length ys -> Length (xs ++ ys)
lengthApp sx Z = sx
lengthApp sx (S sy) = S (lengthApp sx sy)
public export
0 lengthIrrel : (sx1, sx2 : Length xs) -> sx1 = sx2
lengthIrrel Z Z = Refl
lengthIrrel (S sx1) (S sx2) = cong S $ lengthIrrel sx1 sx2