Copyright | Guillaume Sabbagh 2022 |
---|---|
License | LGPL-3.0-or-later |
Maintainer | guillaumesabbagh@protonmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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 may collide with Data.Set.
Synopsis
- data Set a
- set :: [a] -> Set a
- setToList :: Eq a => Set a -> [a]
- isIncludedIn :: Eq a => Set a -> Set a -> Bool
- cardinal :: Eq a => Set a -> Int
- isIn :: Eq a => a -> Set a -> Bool
- (|&|) :: Eq a => Set a -> Set a -> Set a
- (|||) :: Set a -> Set a -> Set a
- (|*|) :: Set a -> Set b -> Set (a, b)
- (|+|) :: Set a -> Set b -> Set (Either a b)
- (|-|) :: Eq a => Set a -> Set a -> Set a
- (|^|) :: (Num a, Eq a) => Set a -> a -> Set [a]
- powerSet :: Set a -> Set (Set a)
- filterSet :: (a -> Bool) -> Set a -> Set a
- nubSetBy :: (a -> a -> Bool) -> Set a -> Set a
- setToMaybe :: Set a -> Maybe a
- maybeToSet :: Maybe a -> Set a
- catMaybesToSet :: Set (Maybe a) -> Set a
- mapMaybeToSet :: (a -> Maybe b) -> Set a -> Set b
Set datatype and smart constructor
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.
Instances
Monad Set Source # | |
Functor Set Source # | |
Applicative Set Source # | |
Foldable Set Source # | |
Defined in Data.WeakSets.HomogeneousSet fold :: Monoid m => Set m -> m foldMap :: Monoid m => (a -> m) -> Set a -> m foldMap' :: Monoid m => (a -> m) -> Set a -> m foldr :: (a -> b -> b) -> b -> Set a -> b foldr' :: (a -> b -> b) -> b -> Set a -> b foldl :: (b -> a -> b) -> b -> Set a -> b foldl' :: (b -> a -> b) -> b -> Set a -> b foldr1 :: (a -> a -> a) -> Set a -> a foldl1 :: (a -> a -> a) -> Set a -> a elem :: Eq a => a -> Set a -> Bool maximum :: Ord a => Set a -> a | |
Eq a => Eq (Set a) Source # | |
Show a => Show (Set a) Source # | |
Semigroup (Set a) Source # | |
Monoid (Set a) Source # | |
O(1). 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 related functions
setToList :: Eq a => Set a -> [a] Source #
O(n). Transform a Set
back into a list, the list returned does not have duplicate elements, the order of the original list holds.
isIncludedIn :: Eq a => Set a -> Set a -> Bool Source #
O(n^2). Return a boolean indicating if a Set
is included in another one.
(|^|) :: (Num a, Eq a) => Set a -> a -> Set [a] Source #
Returns the cartesian product of a set with itself n times.
nubSetBy :: (a -> a -> Bool) -> Set a -> Set a Source #
O(n). Remove duplicates in the set using your own equality function.
Functions to work with Maybe
setToMaybe :: Set a -> Maybe a Source #
O(1). Set version of listToMaybe.
maybeToSet :: Maybe a -> Set a Source #
O(1). Set version of maybeToList.
catMaybesToSet :: Set (Maybe a) -> Set a Source #
O(n). Set version of catMaybes.
mapMaybeToSet :: (a -> Maybe b) -> Set a -> Set b Source #
O(n). Set version of mapMaybe.