on master help sign in
Add Data.List to base

Currently just includes 'Elem' and 'isElem' to decide membership.

commit59b9a4cb888a180061dfa8dbe914e251d93c855e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 10 May 2014, 19:01 (12 years ago) parent0c1bc8d
2 files changed+29
libs/base/Data/List.idr+28 libs/base/base.ipkg+1
libs/base/Data/List.idrnew file+28
@@ -0,0 +1,28 @@
1+module Data.List
2+
3+%access public
4+
5+using (xs : List a)
6+ ||| A proof that some element is found in a list
7+ data Elem : a -> List a -> Type where
8+ Here : Elem x (x :: xs)
9+ There : Elem x xs -> Elem x (y :: xs)
10+
11+ instance Uninhabited (Elem {a} x []) where
12+ uninhabited Here impossible
13+ uninhabited (There p) impossible
14+
15+ private
16+ mkNo : ((x = y) -> _|_) -> (Elem x xs -> _|_) -> Elem x (y :: xs) -> _|_
17+ mkNo f g Here = f refl
18+ mkNo f g (There x) = g x
19+
20+ isElem : DecEq a => (x : a) -> (xs : List a) -> Dec (Elem x xs)
21+ isElem x [] = No absurd
22+ isElem x (y :: xs) with (decEq x y)
23+ isElem x (x :: xs) | (Yes refl) = Yes Here
24+ isElem x (y :: xs) | (No contra) with (isElem x xs)
25+ isElem x (y :: xs) | (No contra) | (Yes prf) = Yes (There prf)
26+ isElem x (y :: xs) | (No contra) | (No f) = No (mkNo contra f)
27+
28+
libs/base/base.ipkg+1
@@ -23,6 +23,7 @@ modules = System,
2323 Data.Vect, Data.HVect, Data.Vect.Quantifiers,
2424 Data.Floats, Data.Complex, Data.Heap, Data.Fun,
2525 Data.Rel, Data.Buffer, Data.Erased,
26+ Data.List,
2627
2728 Control.Isomorphism, Control.Isomorphism.Primitives,
2829 Control.Monad.Identity,