{-| Module : FiniteCategories Description : Utilitary functions for sets with list as underlying representation. Copyright : Guillaume Sabbagh 2021 License : GPL-3 Maintainer : guillaumesabbagh@protonmail.com Stability : experimental Portability : portable Utilitary functions for sets with list as underlying representation. It has the advantage of not requiring the Ord typeclass at all. -} module Utils.SetList ( isIncludedIn, doubleInclusion, powerList ) where -- | Returns a boolean indicating if the set of elements of a list are included in an another. isIncludedIn :: (Eq a) => [a] -> [a] -> Bool [] `isIncludedIn` _ = True (x:xs) `isIncludedIn` l2 | x `elem` l2 = xs `isIncludedIn` l2 | otherwise = False -- | Returns a boolean indicating if the set of elements of two lists are equal. doubleInclusion :: (Eq a) => [a] -> [a] -> Bool l1 `doubleInclusion` l2 = (l1 `isIncludedIn` l2) && (l2 `isIncludedIn` l1) -- | Returns the list of all sublists of a list. powerList :: (Eq a) => [a] -> [[a]] powerList [] = [[]] powerList (x:xs) = (powerList xs) ++ ((x:) <$> (powerList xs))