-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple set types. Useful to create sets of arbitrary types and nested sets. -- -- This package answers two problems : how to make sets of types which -- does not implement the Ord typeclass and how to make arbitrarily -- nested sets as set theory allows. The first problem is resolved thanks -- to HomogeneousSet which is a list where duplicates elements are -- not allowed and the order of elements is forgotten. The second problem -- is resolved thanks to PureSet, it is a tree structure where the -- order of the branches does not matter. @package WeakSets @version 0.2.0.0 -- | Homogeneous sets are sets which can contain only one type of values. -- -- They are more flexible than Data.Set because they do not require the -- objects contained to be orderable. -- -- The datatype only assumes its components are equatable, it is -- therefore slower than the Data.Set datatype. -- -- We use this datatype because most of the datatypes we care about are -- not orderable. -- -- Inline functions related to homogeneous sets are written between pipes -- |. -- -- Function names should not collide with Prelude but should collide with -- Data.Set. module HomogeneousSet -- | A homogeneous set is a list of values. -- -- The only differences are that we don't want duplicate elements and we -- don't need the order of the list elements. -- -- To force these constraints, the Set constructor is abstract and -- is not exported. The only way to construct a set is to use the smart -- constructor set which ensures the previous conditions. data Set a -- | The smart constructor of sets. This is the only way of instantiating a -- Set. -- -- If several elements are equal, they are kept until the user wants a -- list back. set :: [a] -> Set a -- | Transform a Set back into a list, the list returned does not -- have duplicate elements, the order of the original list holds. setToList :: Eq a => Set a -> [a] -- | Return a boolean indicating if a Set is included in another -- one. isIncludedIn :: Eq a => Set a -> Set a -> Bool -- | Size of a set. cardinal :: Eq a => Set a -> Int -- | Return wether an element is in a set. isIn :: Eq a => a -> Set a -> Bool -- | Return the intersection of two sets. (|&|) :: Eq a => Set a -> Set a -> Set a -- | Return the union of two sets. (|||) :: Set a -> Set a -> Set a -- | Return the cartesian product of two sets. (|*|) :: Set a -> Set b -> Set (a, b) -- | Return the disjoint union of two sets. (|+|) :: Set a -> Set b -> Set (Either a b) -- | Return the difference of two sets. (|-|) :: Eq a => Set a -> Set a -> Set a -- | Returns the cartesian product of a set with itself n times. (|^|) :: (Num a, Eq a) => Set a -> a -> Set [a] -- | Return the set of all subsets of a given set. powerSet :: Set a -> Set (Set a) -- | Filter a set according to a condition. filterSet :: (a -> Bool) -> Set a -> Set a -- | Set version of listToMaybe. setToMaybe :: Set a -> Maybe a -- | Set version of maybeToList. maybeToSet :: Maybe a -> Set a -- | Set version of catMaybes. catMaybesToSet :: Set (Maybe a) -> Set a -- | Set version of mapMaybe. mapMaybeToSet :: (a -> Maybe b) -> Set a -> Set b -- | An association list is a list of pairs (key,value). type AssociationList a b = [(a, b)] -- | A function of homogeneous sets. It is a set of pairs (key,value) such -- that their should only be one pair with a given key. -- -- It is an abstract type, the smart constructor is function. data Function a b -- | The smart constructor of functions. This is the only way of -- instantiating a Function. -- -- Takes an association list and returns a function which maps to each -- key the value associated. -- -- If several pairs have the same keys, they are kept until the user -- wants an association list back. function :: AssociationList a b -> Function a b -- | Transform a function back into its underlying association list. functionToSet :: Eq a => Function a b -> Set (a, b) -- | Return the domain of a function. domain :: Function a b -> Set a -- | Return the image of a function. The image of a function is the set of -- values which are reachable by applying the function. image :: Function a b -> Set b -- | Apply a function to a given value. If the function is not defined on -- the given value returns Nothing, otherwise returns Just -- the image. -- -- This function is like lookup in Data.Map for function (the -- order of the argument are reversed though). (|$|) :: Eq a => Function a b -> a -> Maybe b -- | Unsafe version of (|$|). -- -- This function is like (!) in Data.Map for function. (|!|) :: Eq a => Function a b -> a -> b -- | Apply a function to a given value, if the value is in the domain -- returns the image, otherwise return a default value. -- -- This function is like findWithDefault in Data.Map for function -- (the order of the argument are reversed though). findWithDefault :: Eq a => Function a b -> b -> a -> b -- | Compose two functions. If the two functions are not composable, strips -- the functions until they can compose. (|.|) :: (Eq a, Eq b) => Function b c -> Function a b -> Function a c -- | Memorize a Haskell function on a given finite domain. memorizeFunction :: (a -> b) -> Set a -> Function a b instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (HomogeneousSet.Function a b) instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (HomogeneousSet.Function a b) instance GHC.Show.Show a => GHC.Show.Show (HomogeneousSet.Set a) instance GHC.Classes.Eq a => GHC.Classes.Eq (HomogeneousSet.Set a) instance GHC.Classes.Eq a => GHC.Base.Semigroup (HomogeneousSet.Set a) instance GHC.Classes.Eq a => GHC.Base.Monoid (HomogeneousSet.Set a) instance Data.Foldable.Foldable HomogeneousSet.Set instance GHC.Base.Functor HomogeneousSet.Set instance GHC.Base.Applicative HomogeneousSet.Set instance GHC.Base.Monad HomogeneousSet.Set -- | Pure sets are nested sets which only contain other sets all the way -- down. They allow to explore basic set theory. -- -- Every mathematical object is a set, usual constructions such as Von -- Neumann numbers and Kuratowski pairs are implemented. -- -- It is a tree where the order of the branches does not matter. -- -- Functions with the same name as homogeneous set functions are suffixed -- with the letter P for pure to avoid name collision. module PureSet -- | A PureSet is a Set of other pure sets. data PureSet PureSet :: Set PureSet -> PureSet -- | Construct a PureSet from a list of pure sets. pureSet :: [PureSet] -> PureSet -- | Construct the empty set. emptySet :: PureSet -- | Construct the singleton containing a given set. singleton :: PureSet -> PureSet -- | Construct an ordered pair from two sets according to Kuratowski's -- definition of a tuple. pair :: PureSet -> PureSet -> PureSet -- | Construct the cartesian product of two sets. cartesianProduct :: PureSet -> PureSet -> PureSet -- | Transform a number into its Von Neumann construction numberToSet :: (Num a, Eq a) => a -> PureSet -- | Union of two pure sets. (||||) :: PureSet -> PureSet -> PureSet -- | Intersection of two pure sets. (&&&&) :: PureSet -> PureSet -> PureSet -- | Return wether a pure set is in another one. isInP :: PureSet -> PureSet -> Bool -- | Return wether a pure set is included in another one. isIncludedInP :: PureSet -> PureSet -> Bool -- | Return the size of a pure set. card :: PureSet -> Int -- | Return the set of subsets of a given set. powerSetP :: PureSet -> PureSet -- | Prettiffy a pure set according to usual mathematical notation. prettify :: PureSet -> String -- | Format pure sets such that if numbers are recognized, they are -- transformed into integer and if pairs are recognized, they are -- transformed into pairs. formatPureSet :: PureSet -> String instance GHC.Classes.Eq PureSet.PureSet instance GHC.Show.Show PureSet.PureSet