WeakSets-0.4.0.0: Simple set types. Useful to create sets of arbitrary types and nested sets.
CopyrightGuillaume Sabbagh 2022
LicenseLGPL-3.0-or-later
Maintainerguillaumesabbagh@protonmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.WeakSets.HomogeneousSet

Description

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

Set datatype and smart constructor

data Set a Source #

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

Instances details
Monad Set Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

(>>=) :: Set a -> (a -> Set b) -> Set b

(>>) :: Set a -> Set b -> Set b

return :: a -> Set a

Functor Set Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

fmap :: (a -> b) -> Set a -> Set b

(<$) :: a -> Set b -> Set a

Applicative Set Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

pure :: a -> Set a

(<*>) :: Set (a -> b) -> Set a -> Set b

liftA2 :: (a -> b -> c) -> Set a -> Set b -> Set c

(*>) :: Set a -> Set b -> Set b

(<*) :: Set a -> Set b -> Set a

Foldable Set Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

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

toList :: Set a -> [a]

null :: Set a -> Bool

length :: Set a -> Int

elem :: Eq a => a -> Set a -> Bool

maximum :: Ord a => Set a -> a

minimum :: Ord a => Set a -> a

sum :: Num a => Set a -> a

product :: Num a => Set a -> a

Eq a => Eq (Set a) Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

(==) :: Set a -> Set a -> Bool

(/=) :: Set a -> Set a -> Bool

Show a => Show (Set a) Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

showsPrec :: Int -> Set a -> ShowS

show :: Set a -> String

showList :: [Set a] -> ShowS

Semigroup (Set a) Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

(<>) :: Set a -> Set a -> Set a

sconcat :: NonEmpty (Set a) -> Set a

stimes :: Integral b => b -> Set a -> Set a

Monoid (Set a) Source # 
Instance details

Defined in Data.WeakSets.HomogeneousSet

Methods

mempty :: Set a

mappend :: Set a -> Set a -> Set a

mconcat :: [Set a] -> Set a

set :: [a] -> 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.

cardinal :: Eq a => Set a -> Int Source #

O(n). Size of a set.

isIn :: Eq a => a -> Set a -> Bool Source #

O(n). Return wether an element is in a set.

(|&|) :: Eq a => Set a -> Set a -> Set a Source #

O(n*m). Return the intersection of two sets.

(|||) :: Set a -> Set a -> Set a Source #

O(n). Return the union of two sets.

(|*|) :: Set a -> Set b -> Set (a, b) Source #

O(n*m). Return the cartesian product of two sets.

(|+|) :: Set a -> Set b -> Set (Either a b) Source #

O(n). Return the disjoint union of two sets.

(|-|) :: Eq a => Set a -> Set a -> Set a Source #

O(n*m). Return the difference of two sets.

(|^|) :: (Num a, Eq a) => Set a -> a -> Set [a] Source #

Returns the cartesian product of a set with itself n times.

powerSet :: Set a -> Set (Set a) Source #

Return the set of all subsets of a given set.

filterSet :: (a -> Bool) -> Set a -> Set a Source #

O(n). Filter a set according to a condition.

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.