@@ -2,30 +2,29 @@ module Data.List
3%access public
3%access public
6− ||| A proof that some element is found in a list
5+||| A proof that some element is found in a list
7− data Elem : a -> List a -> Type where
6+data Elem : a -> List a -> Type where
8− Here : Elem x (x :: xs)
7+ Here : Elem x (x :: xs)
9− There : Elem x xs -> Elem x (y :: xs)
8+ There : Elem x xs -> Elem x (y :: xs)
11− instance Uninhabited (Elem {a} x []) where
10+instance Uninhabited (Elem {a} x []) where
12− uninhabited Here impossible
11+ uninhabited Here impossible
13− uninhabited (There p) impossible
12+ uninhabited (There p) impossible
15− ||| Is the given element a member of the given list.
14+||| Is the given element a member of the given list.
17− ||| @x The element to be tested.
16+||| @x The element to be tested.
18− ||| @xs The list to be checked against
17+||| @xs The list to be checked against
19− isElem : DecEq a => (x : a) -> (xs : List a) -> Dec (Elem x xs)
18+isElem : DecEq a => (x : a) -> (xs : List a) -> Dec (Elem x xs)
20− isElem x [] = No absurd
19+isElem x [] = No absurd
21− isElem x (y :: xs) with (decEq x y)
20+isElem x (y :: xs) with (decEq x y)
22− isElem x (x :: xs) | (Yes refl) = Yes Here
21+ isElem x (x :: xs) | (Yes refl) = Yes Here
23− isElem x (y :: xs) | (No contra) with (isElem x xs)
22+ isElem x (y :: xs) | (No contra) with (isElem x xs)
24− isElem x (y :: xs) | (No contra) | (Yes prf) = Yes (There prf)
23+ isElem x (y :: xs) | (No contra) | (Yes prf) = Yes (There prf)
25− isElem x (y :: xs) | (No contra) | (No f) = No (mkNo contra f)
24+ isElem x (y :: xs) | (No contra) | (No f) = No (mkNo contra f)
27− mkNo : {xs' : List a} ->
26+ mkNo : {xs' : List a} ->
28− ((x' = y') -> _|_) -> (Elem x' xs' -> _|_) ->
27+ ((x' = y') -> _|_) -> (Elem x' xs' -> _|_) ->
29− Elem x' (y' :: xs') -> _|_
28+ Elem x' (y' :: xs') -> _|_
30− mkNo f g Here = f refl
29+ mkNo f g Here = f refl
31− mkNo f g (There x) = g x
30+ mkNo f g (There x) = g x