language-toolkit-1.2.0.0: A set of tools for analyzing languages via logic and automata
Copyright(c) 2016-2023 Dakotah Lambert
LicenseMIT
Safe HaskellTrustworthy
LanguageHaskell2010
Extensions
  • Cpp
  • TypeSynonymInstances
  • FlexibleInstances
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • FunctionalDependencies

LTK.Containers

Description

contain other entities.

Synopsis

Documentation

class Container c a | c -> a where #

The Container class is used for types that can contain objects and can be combined with union, intersection, and difference (relative complement). Instances of Container should satisfy the following laws:

isIn == flip contains
isNotIn == flip doesNotContain
doesNotContain a == not . contains a
contains a empty == False
contains a (singleton b) == (a == b)
contains a (insert b c) == (a == b) || contains a c
contains a (union c1 c2) == contains a c1 || contains a c2
contains a (intersection c1 c2) == contains a c1 && contains a c2
intersection c c == c
difference c c == empty

Minimal complete definition

(contains | isIn), union, intersection, difference, empty, isEmpty, (insert | singleton)

Methods

isIn :: c -> a -> Bool #

isNotIn :: c -> a -> Bool #

contains :: a -> c -> Bool #

doesNotContain :: a -> c -> Bool #

isEmpty :: c -> Bool #

union :: c -> c -> c #

(union a b) returns a collection of elements that are in one of a or b, or both.

intersection :: c -> c -> c #

(intersection a b) returns a collection of elements that are in both a and b.

difference :: c -> c -> c #

(difference a b) returns a collection of elements that are in a but not in b.

symmetricDifference :: c -> c -> c #

(symmetricDifference a b) returns a collection of elements that are in one of a or b, but not both.

empty :: c #

insert :: a -> c -> c #

singleton :: a -> c #

isSubsetOf :: c -> c -> Bool #

(isSubsetOf y x) tells if x is a subset of y.

isSupersetOf :: c -> c -> Bool #

(isSupersetOf y x) tells if x is a superset of y.

isProperSubsetOf :: c -> c -> Bool #

(isProperSubsetOf y x) tells whether x is a proper subset of y.

isProperSupersetOf :: c -> c -> Bool #

(isProperSupersetOf y x) tells whether x is a proper superset of y.

Instances

Instances details
Ord a => Container (Set a) a # 
Instance details

Defined in LTK.Containers

Methods

isIn :: Set a -> a -> Bool #

isNotIn :: Set a -> a -> Bool #

contains :: a -> Set a -> Bool #

doesNotContain :: a -> Set a -> Bool #

isEmpty :: Set a -> Bool #

union :: Set a -> Set a -> Set a #

intersection :: Set a -> Set a -> Set a #

difference :: Set a -> Set a -> Set a #

symmetricDifference :: Set a -> Set a -> Set a #

empty :: Set a #

insert :: a -> Set a -> Set a #

singleton :: a -> Set a #

isSubsetOf :: Set a -> Set a -> Bool #

isSupersetOf :: Set a -> Set a -> Bool #

isProperSubsetOf :: Set a -> Set a -> Bool #

isProperSupersetOf :: Set a -> Set a -> Bool #

Ord a => Container (Multiset a) a # 
Instance details

Defined in LTK.Containers

Container [a] a # 
Instance details

Defined in LTK.Containers

Methods

isIn :: [a] -> a -> Bool #

isNotIn :: [a] -> a -> Bool #

contains :: a -> [a] -> Bool #

doesNotContain :: a -> [a] -> Bool #

isEmpty :: [a] -> Bool #

union :: [a] -> [a] -> [a] #

intersection :: [a] -> [a] -> [a] #

difference :: [a] -> [a] -> [a] #

symmetricDifference :: [a] -> [a] -> [a] #

empty :: [a] #

insert :: a -> [a] -> [a] #

singleton :: a -> [a] #

isSubsetOf :: [a] -> [a] -> Bool #

isSupersetOf :: [a] -> [a] -> Bool #

isProperSubsetOf :: [a] -> [a] -> Bool #

isProperSupersetOf :: [a] -> [a] -> Bool #

Ord e => Container (ForbiddenSubstrings e) (TaggedSubstring e) # 
Instance details

Defined in LTK.Extract.SL

Ord e => Container (ForbiddenSubsequences e) [e] # 
Instance details

Defined in LTK.Extract.SP

(Enum n, Ord n, Ord e) => Container (FSA n e) [e] # 
Instance details

Defined in LTK.FSA

Methods

isIn :: FSA n e -> [e] -> Bool #

isNotIn :: FSA n e -> [e] -> Bool #

contains :: [e] -> FSA n e -> Bool #

doesNotContain :: [e] -> FSA n e -> Bool #

isEmpty :: FSA n e -> Bool #

union :: FSA n e -> FSA n e -> FSA n e #

intersection :: FSA n e -> FSA n e -> FSA n e #

difference :: FSA n e -> FSA n e -> FSA n e #

symmetricDifference :: FSA n e -> FSA n e -> FSA n e #

empty :: FSA n e #

insert :: [e] -> FSA n e -> FSA n e #

singleton :: [e] -> FSA n e #

isSubsetOf :: FSA n e -> FSA n e -> Bool #

isSupersetOf :: FSA n e -> FSA n e -> Bool #

isProperSubsetOf :: FSA n e -> FSA n e -> Bool #

isProperSupersetOf :: FSA n e -> FSA n e -> Bool #

class Linearizable (l :: Type -> Type) where #

The Linearizable class is used for types that can be traversed linearly in one direction.

Methods

choose :: l a -> (a, l a) #

Return the next element and the collection of remaining elements.

Instances

Instances details
Linearizable Set # 
Instance details

Defined in LTK.Containers

Methods

choose :: Set a -> (a, Set a) #

Linearizable Multiset # 
Instance details

Defined in LTK.Containers

Methods

choose :: Multiset a -> (a, Multiset a) #

Linearizable [] # 
Instance details

Defined in LTK.Containers

Methods

choose :: [a] -> (a, [a]) #

chooseOne :: Linearizable l => l a -> a #

Like choose, but discards the remaining elements.

discardOne :: Linearizable l => l a -> l a #

Like choose, but discards the next element.

class Linearizable c => Collapsible (c :: Type -> Type) where #

The Collapsible class is used for types that can be collapsed to a single value, like a fold over a list. Any structure \(c\) that is Collapsible must necessarily be Linearizable, since:

collapse (:) [] c

performs a linearization.

Minimal complete definition

collapse | size

Methods

collapse :: (a -> b -> b) -> b -> c a -> b #

size :: Integral a => c b -> a #

Instances

Instances details
Collapsible Set # 
Instance details

Defined in LTK.Containers

Methods

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

size :: Integral a => Set b -> a #

Collapsible Multiset # 
Instance details

Defined in LTK.Containers

Methods

collapse :: (a -> b -> b) -> b -> Multiset a -> b #

size :: Integral a => Multiset b -> a #

Collapsible [] # 
Instance details

Defined in LTK.Containers

Methods

collapse :: (a -> b -> b) -> b -> [a] -> b #

size :: Integral a => [b] -> a #

isize :: Collapsible c => c b -> Integer #

The size of the input as an integer

zsize :: Collapsible c => c b -> Bool #

Analogue to isEmpty for Collapsible structures

fromCollapsible :: (Collapsible s, Container c a) => s a -> c #

Build a Container from the elements of a Collapsible. This can be used to cast between most types of Container. Time complexity is \(O(nci)\), where \(n\) is the number of elements in the source, \(c\) is the cost of accessing a next element of the source, and \(i\) is the cost of inserting an element into the destination.

Combining multiple Containers

unionAll :: (Container c a, Collapsible s) => s c -> c #

Combine Containers with union.

intersectAll :: (Container c a, Eq a, Collapsible s) => s c -> c #

Combine Containers with intersection. An empty source yields an empty result.

interleave :: (Linearizable c, Container (c a) a) => c a -> c a -> c a #

Combine two linearizable containers such that the elements of the first and second are inserted in an interleaving manner. For lists, this guarantees that a finite initial segment will contain elements from each, in contrast to the (++) operator.

Since: 0.3

Generic versions of Prelude functions and similar

anyS :: Collapsible s => (a -> Bool) -> s a -> Bool #

True iff some element satisfies a predicate.

allS :: Collapsible s => (a -> Bool) -> s a -> Bool #

True iff all elements satisfy a predicate.

both :: (a -> Bool) -> (a -> Bool) -> a -> Bool #

True iff the given object satisfies both given predicates.

Since: 0.3

tmap :: (Collapsible s, Container (s b1) b) => (a -> b) -> s a -> s b1 #

Appy a function to each element of a Collapsible.

keep :: (Collapsible s, Container (s a) a) => (a -> Bool) -> s a -> s a #

Retain only those elements that satisfy a predicate.

groupBy :: (Eq b, Collapsible s, Container (s a) a, Container (s (s a)) (s a)) => (a -> b) -> s a -> s (s a) #

Partition a Container. For example,

groupBy (`mod` 3) [0..9] == [[0,3,6,9],[1,4,7],[2,5,8]]

partitionBy :: (Ord a, Ord n) => (n -> a) -> Set n -> Set (Set n) #

A fast groupBy for Set objects.

Since: 0.2

refinePartitionBy :: (Ord a, Ord n) => (n -> a) -> Set (Set n) -> Set (Set n) #

A convenience function for the partition refinement operation.

Since: 0.2

Multisets

data Multiset a #

A Multiset is a Set that may contain more than one instance of any given element.

Instances

Instances details
Collapsible Multiset # 
Instance details

Defined in LTK.Containers

Methods

collapse :: (a -> b -> b) -> b -> Multiset a -> b #

size :: Integral a => Multiset b -> a #

Linearizable Multiset # 
Instance details

Defined in LTK.Containers

Methods

choose :: Multiset a -> (a, Multiset a) #

Ord a => Monoid (Multiset a) # 
Instance details

Defined in LTK.Containers

Methods

mempty :: Multiset a #

mappend :: Multiset a -> Multiset a -> Multiset a #

mconcat :: [Multiset a] -> Multiset a #

Ord a => Semigroup (Multiset a) # 
Instance details

Defined in LTK.Containers

Methods

(<>) :: Multiset a -> Multiset a -> Multiset a #

sconcat :: NonEmpty (Multiset a) -> Multiset a #

stimes :: Integral b => b -> Multiset a -> Multiset a #

(Ord a, Read a) => Read (Multiset a) # 
Instance details

Defined in LTK.Containers

Show a => Show (Multiset a) # 
Instance details

Defined in LTK.Containers

Methods

showsPrec :: Int -> Multiset a -> ShowS #

show :: Multiset a -> String #

showList :: [Multiset a] -> ShowS #

Eq a => Eq (Multiset a) # 
Instance details

Defined in LTK.Containers

Methods

(==) :: Multiset a -> Multiset a -> Bool #

(/=) :: Multiset a -> Multiset a -> Bool #

Ord a => Ord (Multiset a) # 
Instance details

Defined in LTK.Containers

Methods

compare :: Multiset a -> Multiset a -> Ordering #

(<) :: Multiset a -> Multiset a -> Bool #

(<=) :: Multiset a -> Multiset a -> Bool #

(>) :: Multiset a -> Multiset a -> Bool #

(>=) :: Multiset a -> Multiset a -> Bool #

max :: Multiset a -> Multiset a -> Multiset a #

min :: Multiset a -> Multiset a -> Multiset a #

Ord a => Container (Multiset a) a # 
Instance details

Defined in LTK.Containers

multiplicity :: Ord a => Multiset a -> a -> Integer #

Analogous to isIn, returning the number of occurrences of an element in a Multiset. Time complexity is \(O(\log{n})\), where \(n\) is the number of distinct elements in the Multiset.

multiplicities :: Ord a => Multiset a -> Set Integer #

Every multiplicity that occurs in the multiset.

Since: 1.0

multisetFromList :: Ord a => [a] -> Multiset a #

A specialization of fromCollapsible.

setFromMultiset :: Multiset a -> Set a #

A specialization of fromCollapsible with time complexity \(O(n)\), where \(n\) is the number of distinct elements in the source.

Set of Set with alternate ordering

The choose instance for Set will always pick the least available element. If one wants to process elements in a different order, one can simply wrap the elements in such a way that they sort in the intended order of processing. This section contains some such wrapper types.

newtype IncreasingSize x #

Wrap a Collapsible type to sort in order of increasing size. For elements of the same size, treat them normally.

Constructors

IncreasingSize 

Fields

Instances

Instances details
Functor IncreasingSize # 
Instance details

Defined in LTK.Containers

Methods

fmap :: (a -> b) -> IncreasingSize a -> IncreasingSize b #

(<$) :: a -> IncreasingSize b -> IncreasingSize a #

Read x => Read (IncreasingSize x) # 
Instance details

Defined in LTK.Containers

Show x => Show (IncreasingSize x) # 
Instance details

Defined in LTK.Containers

Eq x => Eq (IncreasingSize x) # 
Instance details

Defined in LTK.Containers

(Collapsible x, Ord (x a)) => Ord (IncreasingSize (x a)) # 
Instance details

Defined in LTK.Containers

Methods

compare :: IncreasingSize (x a) -> IncreasingSize (x a) -> Ordering #

(<) :: IncreasingSize (x a) -> IncreasingSize (x a) -> Bool #

(<=) :: IncreasingSize (x a) -> IncreasingSize (x a) -> Bool #

(>) :: IncreasingSize (x a) -> IncreasingSize (x a) -> Bool #

(>=) :: IncreasingSize (x a) -> IncreasingSize (x a) -> Bool #

max :: IncreasingSize (x a) -> IncreasingSize (x a) -> IncreasingSize (x a) #

min :: IncreasingSize (x a) -> IncreasingSize (x a) -> IncreasingSize (x a) #

newtype DecreasingSize x #

Wrap a Collapsible type to sort in order of decreasing size. For elements of the same size, treat them normally.

Constructors

DecreasingSize 

Fields

Instances

Instances details
Functor DecreasingSize # 
Instance details

Defined in LTK.Containers

Methods

fmap :: (a -> b) -> DecreasingSize a -> DecreasingSize b #

(<$) :: a -> DecreasingSize b -> DecreasingSize a #

Read x => Read (DecreasingSize x) # 
Instance details

Defined in LTK.Containers

Show x => Show (DecreasingSize x) # 
Instance details

Defined in LTK.Containers

Eq x => Eq (DecreasingSize x) # 
Instance details

Defined in LTK.Containers

(Collapsible x, Ord (x a)) => Ord (DecreasingSize (x a)) # 
Instance details

Defined in LTK.Containers

Methods

compare :: DecreasingSize (x a) -> DecreasingSize (x a) -> Ordering #

(<) :: DecreasingSize (x a) -> DecreasingSize (x a) -> Bool #

(<=) :: DecreasingSize (x a) -> DecreasingSize (x a) -> Bool #

(>) :: DecreasingSize (x a) -> DecreasingSize (x a) -> Bool #

(>=) :: DecreasingSize (x a) -> DecreasingSize (x a) -> Bool #

max :: DecreasingSize (x a) -> DecreasingSize (x a) -> DecreasingSize (x a) #

min :: DecreasingSize (x a) -> DecreasingSize (x a) -> DecreasingSize (x a) #

Miscellaneous classes

class HasAlphabet (g :: Type -> Type) where #

Allow for overloading of the term alphabet.

Since: 0.3

Methods

alphabet :: g e -> Set e #

Instances

Instances details
HasAlphabet SLG # 
Instance details

Defined in LTK.Learn.SL

Methods

alphabet :: SLG e -> Set e #

HasAlphabet SPG # 
Instance details

Defined in LTK.Learn.SP

Methods

alphabet :: SPG e -> Set e #

HasAlphabet TSLG # 
Instance details

Defined in LTK.Learn.TSL.AugmentedSubsequences

Methods

alphabet :: TSLG e -> Set e #

HasAlphabet TSLG # 
Instance details

Defined in LTK.Learn.TSL.ViaSL

Methods

alphabet :: TSLG e -> Set e #

HasAlphabet (FSA n) # 
Instance details

Defined in LTK.FSA

Methods

alphabet :: FSA n e -> Set e #

Miscellaneous functions

extractMonotonic :: (Ord a, Ord b) => (a -> b) -> b -> Set a -> Set a #

A fast method to extract elements from a set whose image under a monotonic function is a certain value. The precondition that the function is monotonic is not checked.

Since: 0.2

sequencesOver :: [x] -> [[x]] #

All possible sequences over a given alphabet, generated in a breadth-first manner.

Since: 0.3

tr :: (Container (s a) a, Collapsible s, Eq a) => [a] -> [a] -> s a -> s a #

Translate elements. All instances of elements of the search set are replaced by the corresponding elements of the replacement set in the given string. If the replacement set is smaller than the search set, it is made longer by repeating the last element.

>>> tr "aeiou" "x" "colorless green ideas"
"cxlxrlxss grxxn xdxxs"
>>> tr "abcdefghijklmnopqrstuvwxyz" "nopqrstuvwxyzabcdefghijklm" "cat"
"png"