0 | module Data.List1.Elem
3 | import Data.List.Elem
5 | import Decidable.Equality
6 | import Control.Function
16 | data Elem : a -> List1 a -> Type where
18 | Here : Elem x (x ::: xs)
20 | There : Elem x xs -> Elem x (y ::: xs)
23 | Uninhabited (List1.Elem.Here {x} {xs} = List1.Elem.There {x = x'} {y} {xs = xs'} e) where
24 | uninhabited Refl
impossible
27 | Uninhabited (List1.Elem.There {x} {y} {xs} e = List1.Elem.Here {x = x'} {xs = xs'}) where
28 | uninhabited Refl
impossible
31 | Injective (List1.Elem.There {x} {y} {xs}) where
32 | injective Refl = Refl
35 | DecEq (List1.Elem.Elem x xs) where
36 | decEq Here Here = Yes Refl
37 | decEq (There this) (There that) = decEqCong $
decEq this that
38 | decEq Here (There later) = No absurd
39 | decEq (There later) Here = No absurd
42 | Uninhabited (x = z) => Uninhabited (Elem z xs) => Uninhabited (Elem z $
x:::xs) where
43 | uninhabited Here @{xz} = uninhabited Refl @{xz}
44 | uninhabited (There y) = uninhabited y
48 | neitherHereNorThere : Not (x = y) -> Not (Elem x xs) -> Not (Elem x (y ::: xs))
49 | neitherHereNorThere xny _ Here = xny Refl
50 | neitherHereNorThere _ xnxs (There xxs) = xnxs xxs
54 | isElem : DecEq a => (x : a) -> (xs : List1 a) -> Dec (List1.Elem.Elem x xs)
55 | isElem x (y ::: xs) with (decEq x y)
56 | isElem x (x ::: xs) | Yes Refl = Yes Here
57 | isElem x (y ::: xs) | No xny with (isElem x xs)
58 | isElem x (y ::: xs) | No xny | Yes xxs = Yes (There xxs)
59 | isElem x (y ::: xs) | No xny | No xnxs = No (neitherHereNorThere xny xnxs)
65 | dropElem : (xs : List1 a) -> (p : Elem x xs) -> List a
66 | dropElem (_ ::: ys) Here = ys
67 | dropElem (x ::: ys) (There p) = x :: dropElem ys p
71 | elemToNat : Data.List1.Elem.Elem x xs -> Nat
73 | elemToNat (There p) = S (elemToNat p)
77 | indexElem : Nat -> (xs : List1 a) -> Maybe (
x ** Elem x xs)
78 | indexElem Z (y ::: _) = Just (
y ** Here)
79 | indexElem (S n) (_ ::: ys) = map (\(
x ** p)
=> (
x ** There p)
) (indexElem n ys)
83 | elemMap : (0 f : a -> b) -> List1.Elem.Elem x xs -> List1.Elem.Elem (f x) (map f xs)
84 | elemMap f Here = Here
85 | elemMap f (There el) = There $
elemMap f el