|
| 1 | +import Data.Vect |
| 2 | + |
| 3 | +public export |
| 4 | +data Chain : (len : Nat) -> (t : Nat -> Type -> Type) |
| 5 | + -> (item : Type) |
| 6 | + -> (m : forall a, b, c . t a c -> t b c -> Type) |
| 7 | + -> (input : t a' item) -> (output : t b' item) -> Type where |
| 8 | + Same : {m : forall a, b, c . t a c -> t b c -> Type} -> Chain 0 t item m x x |
| 9 | + Apply : {m : forall a, b, c . t a c -> t b c -> Type} |
| 10 | + -> (prev : Chain len t item m input intermediate) -> (modification : m intermediate output) |
| 11 | + -> Chain (S len) t item m input output |
| 12 | + |
| 13 | +public export |
| 14 | +interface LawfulChain (t : Nat -> Type -> Type) |
| 15 | + (m : forall a, b, c . t a c -> t b c -> Type) | m where |
| 16 | + apply : (input : t len_input item) |
| 17 | + -> {0 output : t len_output item} -> (chain : Chain len_chain t item m input output) |
| 18 | + -> t len_output item |
| 19 | + applyCorrect : (input : t len_input item) |
| 20 | + -> {0 output : t len_output item} -> (chain : Chain len_chain t item m input output) |
| 21 | + -> (apply input chain) = output |
| 22 | + |
| 23 | +public export |
| 24 | +data Modification : Vect n item -> Vect m item -> Type where |
| 25 | + Insert : {0 prev : Vect n item} -> (idx : Fin (S n)) -> (it : item) |
| 26 | + -> Modification prev (insertAt idx it prev) |
| 27 | + Delete : {0 prev : Vect (S n) item} -> (idx : Fin (S n)) |
| 28 | + -> Modification prev (deleteAt idx prev) |
| 29 | + |
| 30 | +public export |
| 31 | +LawfulChain Vect Modification where |
| 32 | + apply input Same = input |
| 33 | + apply input (Apply prev (Insert idx it)) = insertAt idx it (apply input prev) |
| 34 | + apply input (Apply prev (Delete idx)) = deleteAt idx (apply input prev) |
| 35 | + applyCorrect input chain = ?applyCorrect_rhs |
| 36 | + |
0 commit comments