19 | import Control.Monad.Identity
20 | import public Control.Monad.Reader
21 | import Data.Contravariant
22 | import public Data.List
23 | import public Data.List.Quantifiers
24 | import public Data.Nat
25 | import public Data.Vect
29 | Neq : Nat -> Nat -> Type
30 | Neq x y = Either (LT x y) (GT x y)
37 | range : (n : Nat) -> Vect n Nat
39 | range (S n) = snoc (range n) n
44 | enumerate : Vect n a -> Vect n (Nat, a)
46 | let lengthOK = lengthCorrect xs
47 | in rewrite sym lengthOK in zip (range (length xs)) (rewrite lengthOK in xs)
50 | functorIdentity : forall a . (xs : Vect n a) -> map Prelude.id xs = xs
51 | functorIdentity [] = Refl
52 | functorIdentity (x :: xs) = cong2 (::) Refl (functorIdentity xs)
59 | range : (n : Nat) -> List Nat
60 | range n = toList (Vect.range n)
65 | enumerate : List a -> List (Nat, a)
66 | enumerate xs = toList (enumerate (fromList xs))
72 | unique : Eq a => List a -> Bool
74 | unique (x :: xs) = not (elem x xs) && unique xs
80 | , unique [0, 1] = True
81 | , unique [1, 0] = True
82 | , unique [0, 0] = False
83 | , unique [0, 0, 1] = False
84 | , unique [0, 1, 0] = False
85 | , unique [1, 0, 0] = False
86 | , unique [1, 1, 0] = False
87 | , unique [1, 0, 1] = False
88 | , unique [0, 1, 1] = False
89 | , unique [1, 2, 3] = True
96 | map : (f : (x : a) -> {0 ok : p x} -> b) -> (xs : List a) -> {auto 0 allOk : All p xs} -> List b
97 | map f [] {allOk = []} = []
98 | map f (x :: xs) {allOk = ok :: _} = f {ok} x :: map f xs
106 | multiIndex : (idxs : List Nat) ->
108 | {auto 0 inBounds : All (flip InBounds xs) idxs} ->
110 | multiIndex idxs xs = map f idxs
114 | f : (i : Nat) -> {0 _ : InBounds i xs} -> a
123 | deleteAt : (idxs : List Nat) ->
125 | {auto 0 inBounds : All (flip InBounds xs) idxs} ->
127 | deleteAt idxs xs = impl 0 xs
129 | impl : Nat -> List a -> List a
131 | impl i (x :: xs) = if elem i idxs then impl (S i) xs else x :: impl (S i) xs
134 | functorIdentity : forall a . (xs : List a) -> map Prelude.id xs = xs
135 | functorIdentity [] = Refl
136 | functorIdentity (x :: xs) = cong2 (::) Refl (functorIdentity xs)
140 | data All2 : (0 p : a -> b -> Type) -> List a -> List b -> Type where
142 | (::) : forall xs, ys . p x y -> All2 p xs ys -> All2 p (x :: xs) (y :: ys)
146 | length : All2 f xs ys -> Nat
148 | length (_ :: xs) = S (length xs)
152 | mapProperty : (forall x, y . f x y -> g x y) -> All2 f xs ys -> All2 g xs ys
153 | mapProperty f [] = []
154 | mapProperty f (x :: xs) = f x :: mapProperty f xs
159 | Applicative m => All2 f xs ys -> (forall x, y . f x y -> m (g x y)) -> m (All2 g xs ys)
160 | forProperty [] _ = pure []
161 | forProperty (z :: zs) f = [| f z :: forProperty zs f |]
167 | data Sorted : (a -> a -> Type) -> List a -> Type where
172 | SOne : Sorted f [x]
175 | SCons : (y : a) -> f y x -> Sorted f (x :: xs) -> Sorted f (y :: x :: xs)
179 | inBoundsCons : (xs : List a) -> InBounds k xs -> InBounds k (x :: xs)
180 | inBoundsCons _ InFirst = InFirst
181 | inBoundsCons (_ :: ys) (InLater prf) = InLater (inBoundsCons ys prf)
185 | (>$<) : (env' -> env) -> ReaderT env m a -> ReaderT env' m a
186 | f >$< (MkReaderT g) = MkReaderT (g . f)