@@ -35,10 +35,14 @@ module TypeFun.Data.List
35 , UnionList
35 , UnionList
36 , AppendUniq
36 , AppendUniq
37 , Intersect
37 , Intersect
38 -- * Uniqueness checking
39 -- * Uniqueness checking
39 , ElementIsUniq
40 , ElementIsUniq
40 , UniqElements
41 , UniqElements
41 , UniqElements'
42 , UniqElements'
44import Data.Type.Bool
48import Data.Type.Bool
@@ -47,6 +51,7 @@ import GHC.TypeLits
47import TypeFun.Data.Eq
51import TypeFun.Data.Eq
48import TypeFun.Data.Maybe
52import TypeFun.Data.Maybe
49import TypeFun.Data.Peano
53import TypeFun.Data.Peano
51------------------------------------------------------------------------
56------------------------------------------------------------------------
52-- NOTE: Errors type classes. These type classes are not in separate --
57-- NOTE: Errors type classes. These type classes are not in separate --
@@ -103,6 +108,13 @@ type family (:++:) (a :: [k]) (b :: [k]) :: [k] where
103 '[] :++: b = b
108 '[] :++: b = b
104 (a ': as) :++: b = a ': (as :++: b)
109 (a ': as) :++: b = a ': (as :++: b)
114+ -> (l ~ (l :++: '[]) => r)
116+appendId = unsafeCoerce id
106type IndexOf a s = FromJust (IndexOfMay a s)
118type IndexOf a s = FromJust (IndexOfMay a s)
108type IndexOfMay a s = IndexOfMay' Z a s
120type IndexOfMay a s = IndexOfMay' Z a s
@@ -156,6 +168,12 @@ type family SubList (a :: [k]) (b :: [k]) :: Constraint where
156 SubList '[] bs = ()
168 SubList '[] bs = ()
157 SubList (a ': as) bs = (Elem a bs, SubList as bs)
169 SubList (a ': as) bs = (Elem a bs, SubList as bs)
174+ -> (SubList l l => r) -> r
175+subListId _ = unsafeCoerce id
159type family NotSubList (a :: [k]) (b :: [k]) :: Constraint where
177type family NotSubList (a :: [k]) (b :: [k]) :: Constraint where
160 NotSubList '[] bs = ()
178 NotSubList '[] bs = ()
161 NotSubList (a ': as) bs = (NotElem a bs, NotSubList as bs)
179 NotSubList (a ': as) bs = (NotElem a bs, NotSubList as bs)
@@ -195,6 +213,12 @@ type family AppendUniq (a :: k) (s :: [k]) :: [k] where
195-- taken from first list
213-- taken from first list
196type Intersect a b = (Indices (CatMaybes (IndicesOfMay a b)) b)
214type Intersect a b = (Indices (CatMaybes (IndicesOfMay a b)) b)
216+-- | Removes from first list all elements occured in second
217+type family Substract (a :: [k]) (b :: [k]) :: [k] where
218+ Substract '[] b = '[]
220+ Substract a (b ': bs) = Substract (Delete b a) bs
198-- | Checks that element 'a' occurs in a list just once
222-- | Checks that element 'a' occurs in a list just once
199type ElementIsUniq a s = If (Equal (S Z) (Count a s))
223type ElementIsUniq a s = If (Equal (S Z) (Count a s))
200 (() :: Constraint)
224 (() :: Constraint)