Skip to content

Instantly share code, notes, and snippets.

@edwinb
Created July 7, 2014 10:28
Show Gist options
  • Save edwinb/43133bfa00db338cf116 to your computer and use it in GitHub Desktop.
Save edwinb/43133bfa00db338cf116 to your computer and use it in GitHub Desktop.
Spot the difference
data Elem : a -> Vect n a -> Type where
Here : Elem x (x :: xs)
There : Elem x xs -> Elem x (y :: xs)
isElem : DecEq a => (x : a) -> (xs : _) -> Maybe (Elem x xs)
isElem x [] = Nothing
isElem x (y :: xs) with (decEq x y)
isElem x (x :: xs) | (Yes refl) = Just Here
isElem x (y :: xs) | (No contra) = Just (There !(isElem x xs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment