@@ -9,6 +9,7 @@ module TypeFun.Data.List
13 -- * Elements lookup
14 -- * Elements lookup
@@ -34,10 +35,14 @@ module TypeFun.Data.List
34 , UnionList
35 , UnionList
35 , AppendUniq
36 , AppendUniq
36 , Intersect
37 , Intersect
37 -- * Uniqueness checking
39 -- * Uniqueness checking
38 , ElementIsUniq
40 , ElementIsUniq
39 , UniqElements
41 , UniqElements
40 , UniqElements'
42 , UniqElements'
43import Data.Type.Bool
48import Data.Type.Bool
@@ -46,6 +51,7 @@ import GHC.TypeLits
46import TypeFun.Data.Eq
51import TypeFun.Data.Eq
47import TypeFun.Data.Maybe
52import TypeFun.Data.Maybe
48import TypeFun.Data.Peano
53import TypeFun.Data.Peano
50------------------------------------------------------------------------
56------------------------------------------------------------------------
51-- NOTE: Errors type classes. These type classes are not in separate --
57-- NOTE: Errors type classes. These type classes are not in separate --
@@ -92,10 +98,23 @@ type family Delete (a :: k) (s :: [k]) :: [k] where
92 Delete a (a ': as) = Delete a as
98 Delete a (a ': as) = Delete a as
93 Delete a (b ': as) = b ': (Delete a as)
99 Delete a (b ': as) = b ': (Delete a as)
101+-- | Remove index from the list
102+type family Remove (i :: N) (a :: [k]) :: [k] where
104+ Remove 'Z (a ': as) = as
105+ Remove ('S i) (a ': as) = a ': (Remove i as)
95type family (:++:) (a :: [k]) (b :: [k]) :: [k] where
107type family (:++:) (a :: [k]) (b :: [k]) :: [k] where
96 '[] :++: b = b
108 '[] :++: b = b
97 (a ': as) :++: b = a ': (as :++: b)
109 (a ': as) :++: b = a ': (as :++: b)
114+ -> (l ~ (l :++: '[]) => r)
116+appendId = unsafeCoerce id
99type IndexOf a s = FromJust (IndexOfMay a s)
118type IndexOf a s = FromJust (IndexOfMay a s)
101type IndexOfMay a s = IndexOfMay' Z a s
120type IndexOfMay a s = IndexOfMay' Z a s
@@ -149,6 +168,12 @@ type family SubList (a :: [k]) (b :: [k]) :: Constraint where
149 SubList '[] bs = ()
168 SubList '[] bs = ()
150 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
152type family NotSubList (a :: [k]) (b :: [k]) :: Constraint where
177type family NotSubList (a :: [k]) (b :: [k]) :: Constraint where
153 NotSubList '[] bs = ()
178 NotSubList '[] bs = ()
154 NotSubList (a ': as) bs = (NotElem a bs, NotSubList as bs)
179 NotSubList (a ': as) bs = (NotElem a bs, NotSubList as bs)
@@ -188,6 +213,12 @@ type family AppendUniq (a :: k) (s :: [k]) :: [k] where
188-- taken from first list
213-- taken from first list
189type 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
191-- | Checks that element 'a' occurs in a list just once
222-- | Checks that element 'a' occurs in a list just once
192type ElementIsUniq a s = If (Equal (S Z) (Count a s))
223type ElementIsUniq a s = If (Equal (S Z) (Count a s))
193 (() :: Constraint)
224 (() :: Constraint)