39 lines
863 B
Idris
39 lines
863 B
Idris
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)
|
|
|
|
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
|