0 | ||| Utility functions for manipulating collection quantifiers
 1 | module Deriving.SpecialiseData.Utils.Quantifiers
 2 |
 3 | import public Data.DPair -- workaround for idris-lang/Idris2#2439
 4 | import Data.List
 5 | import Data.List.Quantifiers
 6 | import Data.Vect
 7 | import Data.Vect.Quantifiers
 8 | import Data.SnocList.Quantifiers
 9 |
10 | namespace VectAll
11 |   ||| Proof that Vect.All works over Vect.snoc
12 |   export
13 |   0 snoc: All p prev -> p new -> All p (Data.Vect.snoc prev new)
14 |   snoc [] y = [y]
15 |   snoc (y :: ys) z = y :: snoc ys z
16 |
17 |   ||| List + List.All to Vect + Vect.All
18 |   export
19 |   fromListAll : (l : List t) -> (0 pr : All p l) => Subset (Vect (length l) t) (All p)
20 |   fromListAll [] = Element [] []
21 |   fromListAll (x :: xs) @{p :: ps} = do
22 |     let Element xs' ps' = fromListAll xs @{ps}
23 |     Element (x :: xs') (p :: ps')
24 |
25 | namespace ListAll
26 |   ||| Proof that List.All works over List.snoc
27 |   export
28 |   0 snoc : All p prev -> p new -> All p (Data.List.snoc prev new)
29 |   snoc [] y = [y]
30 |   snoc (y :: ys) z = y :: snoc ys z
31 |
32 | namespace SnocListAll
33 |   ||| SnocList + SnocList.All to List + List.All
34 |   export
35 |   toListAll : (sl : SnocList t) -> (0 _ : All p sl) -> Subset (List t) (All p)
36 |   toListAll [<] [<] = Element [] []
37 |   toListAll (sx :< x) (sy :< y) = do
38 |     let Element xs ys = toListAll sx sy
39 |     Element (snoc xs x) (snoc ys y)
40 |
41 |