Skip to content

Instantly share code, notes, and snippets.

@jfdm
Last active September 13, 2016 20:27
Show Gist options
  • Save jfdm/23f9e731ddc473861ab6cbfe268e2ea9 to your computer and use it in GitHub Desktop.
Save jfdm/23f9e731ddc473861ab6cbfe268e2ea9 to your computer and use it in GitHub Desktop.
module Data.List.Constraints
import Data.Vect
data NotElem : a -> List a -> Type where
NotHere : NotElem x []
NotThere : Eq ty => {x,y : ty} -> {auto prf : x /= y = True} -> NotElem x xs -> NotElem x (y::xs)
data AllDiff : List a -> Type where
EmptyCase : AllDiff Nil
OneCase : AllDiff [x]
ManyCase : NotElem x xs -> AllDiff xs -> AllDiff (x::xs)
data UniqueList : (a : Type) -> List a -> Type where
Nil : UniqueList ty Nil
(::) : (x : ty)
-> (xs : UniqueList ty xs')
-> {auto prf : NotElem x xs'}
-> {auto prf : AllDiff (x::xs')}
-> UniqueList ty (x::xs')
UniqueList' : Type -> Type
UniqueList' ty = Subset (List ty) (\xs => AllDiff xs)
fromList : Eq a
=> (xs : List a)
-> {auto prf : AllDiff xs}
-> UniqueList' a
fromList xs {prf} = Element xs prf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment