hgeometry-combinatorial-0.12.0.0: Data structures, and Data types.
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageHaskell2010

Data.LSeq

Description

 
Synopsis

Documentation

data LSeq (n :: Nat) a where Source #

LSeq n a certifies that the sequence has *at least* n items

Bundled Patterns

pattern EmptyL :: LSeq n a

The empty sequence.

pattern (:<|) :: a -> LSeq n a -> LSeq (1 + n) a infixr 5

A bidirectional pattern synonym viewing the front of a non-empty sequence.

pattern (:<<) :: a -> LSeq 0 a -> LSeq n a infixr 5

A unidirectional pattern synonym viewing the front of a non-empty sequence.

pattern (:|>) :: forall n a. LSeq n a -> a -> LSeq (1 + n) a infixl 5

A bidirectional pattern synonym viewing the rear of a non-empty sequence.

Instances

Instances details
Functor (LSeq n) Source # 
Instance details

Defined in Data.LSeq

Methods

fmap :: (a -> b) -> LSeq n a -> LSeq n b #

(<$) :: a -> LSeq n b -> LSeq n a #

Foldable (LSeq n) Source # 
Instance details

Defined in Data.LSeq

Methods

fold :: Monoid m => LSeq n m -> m #

foldMap :: Monoid m => (a -> m) -> LSeq n a -> m #

foldMap' :: Monoid m => (a -> m) -> LSeq n a -> m #

foldr :: (a -> b -> b) -> b -> LSeq n a -> b #

foldr' :: (a -> b -> b) -> b -> LSeq n a -> b #

foldl :: (b -> a -> b) -> b -> LSeq n a -> b #

foldl' :: (b -> a -> b) -> b -> LSeq n a -> b #

foldr1 :: (a -> a -> a) -> LSeq n a -> a #

foldl1 :: (a -> a -> a) -> LSeq n a -> a #

toList :: LSeq n a -> [a] #

null :: LSeq n a -> Bool #

length :: LSeq n a -> Int #

elem :: Eq a => a -> LSeq n a -> Bool #

maximum :: Ord a => LSeq n a -> a #

minimum :: Ord a => LSeq n a -> a #

sum :: Num a => LSeq n a -> a #

product :: Num a => LSeq n a -> a #

Traversable (LSeq n) Source # 
Instance details

Defined in Data.LSeq

Methods

traverse :: Applicative f => (a -> f b) -> LSeq n a -> f (LSeq n b) #

sequenceA :: Applicative f => LSeq n (f a) -> f (LSeq n a) #

mapM :: Monad m => (a -> m b) -> LSeq n a -> m (LSeq n b) #

sequence :: Monad m => LSeq n (m a) -> m (LSeq n a) #

1 <= n => Traversable1 (LSeq n) Source # 
Instance details

Defined in Data.LSeq

Methods

traverse1 :: Apply f => (a -> f b) -> LSeq n a -> f (LSeq n b) #

sequence1 :: Apply f => LSeq n (f b) -> f (LSeq n b) #

1 <= n => Foldable1 (LSeq n) Source # 
Instance details

Defined in Data.LSeq

Methods

fold1 :: Semigroup m => LSeq n m -> m #

foldMap1 :: Semigroup m => (a -> m) -> LSeq n a -> m #

toNonEmpty :: LSeq n a -> NonEmpty a #

Eq a => Eq (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(==) :: LSeq n a -> LSeq n a -> Bool #

(/=) :: LSeq n a -> LSeq n a -> Bool #

Ord a => Ord (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

compare :: LSeq n a -> LSeq n a -> Ordering #

(<) :: LSeq n a -> LSeq n a -> Bool #

(<=) :: LSeq n a -> LSeq n a -> Bool #

(>) :: LSeq n a -> LSeq n a -> Bool #

(>=) :: LSeq n a -> LSeq n a -> Bool #

max :: LSeq n a -> LSeq n a -> LSeq n a #

min :: LSeq n a -> LSeq n a -> LSeq n a #

Read a => Read (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

readsPrec :: Int -> ReadS (LSeq n a) #

readList :: ReadS [LSeq n a] #

readPrec :: ReadPrec (LSeq n a) #

readListPrec :: ReadPrec [LSeq n a] #

Show a => Show (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

showsPrec :: Int -> LSeq n a -> ShowS #

show :: LSeq n a -> String #

showList :: [LSeq n a] -> ShowS #

Generic (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Associated Types

type Rep (LSeq n a) :: Type -> Type #

Methods

from :: LSeq n a -> Rep (LSeq n a) x #

to :: Rep (LSeq n a) x -> LSeq n a #

Semigroup (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(<>) :: LSeq n a -> LSeq n a -> LSeq n a #

sconcat :: NonEmpty (LSeq n a) -> LSeq n a #

stimes :: Integral b => b -> LSeq n a -> LSeq n a #

Monoid (LSeq 0 a) Source # 
Instance details

Defined in Data.LSeq

Methods

mempty :: LSeq 0 a #

mappend :: LSeq 0 a -> LSeq 0 a -> LSeq 0 a #

mconcat :: [LSeq 0 a] -> LSeq 0 a #

(KnownNat n, Arbitrary a) => Arbitrary (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

arbitrary :: Gen (LSeq n a) #

shrink :: LSeq n a -> [LSeq n a] #

ToJSON a => ToJSON (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

toJSON :: LSeq n a -> Value #

toEncoding :: LSeq n a -> Encoding #

toJSONList :: [LSeq n a] -> Value #

toEncodingList :: [LSeq n a] -> Encoding #

FromJSON a => FromJSON (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

parseJSON :: Value -> Parser (LSeq n a) #

parseJSONList :: Value -> Parser [LSeq n a] #

NFData a => NFData (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

rnf :: LSeq n a -> () #

Ixed (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

Methods

ix :: Index (LSeq n a) -> Traversal' (LSeq n a) (IxValue (LSeq n a)) #

type Rep (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

type Rep (LSeq n a) = D1 ('MetaData "LSeq" "Data.LSeq" "hgeometry-combinatorial-0.12.0.0-VIzkyOvE5y1mf3MPLhQ6V" 'True) (C1 ('MetaCons "LSeq" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Seq a))))
type Index (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

type Index (LSeq n a) = Int
type IxValue (LSeq n a) Source # 
Instance details

Defined in Data.LSeq

type IxValue (LSeq n a) = a

toSeq :: LSeq n a -> Seq a Source #

\( O(1) \) Convert to a sequence by dropping the type-level size.

empty :: LSeq 0 a Source #

\( O(1) \) The empty sequence.

fromList :: Foldable f => f a -> LSeq 0 a Source #

\( O(n) \). Create an l-sequence from a finite list of elements.

fromNonEmpty :: NonEmpty a -> LSeq 1 a Source #

\( O(n) \). Create an l-sequence from a non-empty list.

fromSeq :: Seq a -> LSeq 0 a Source #

\( O(n) \). Create an l-sequence from a sequence of elements.

(<|) :: a -> LSeq n a -> LSeq (1 + n) a infixr 5 Source #

\( O(1) \) Add an element to the left end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

(|>) :: LSeq n a -> a -> LSeq (1 + n) a infixl 5 Source #

\( O(1) \) Add an element to the right end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

(><) :: LSeq n a -> LSeq m a -> LSeq (n + m) a infix 5 Source #

\( O(log(min(n,m))) \) Concatenate two sequences.

eval :: forall proxy n m a. KnownNat n => proxy n -> LSeq m a -> Maybe (LSeq n a) Source #

\( O(1) \) Prove a sequence has at least n elements.

>>> eval (Proxy :: Proxy 3) (fromList [1,2,3])
Just (LSeq (fromList [1,2,3]))
>>> eval (Proxy :: Proxy 3) (fromList [1,2])
Nothing
>>> eval (Proxy :: Proxy 3) (fromList [1..10])
Just (LSeq (fromList [1,2,3,4,5,6,7,8,9,10]))

index :: LSeq n a -> Int -> a Source #

\( O(log(min(i,n-i))) \) Get the element with index i, counting from the left and starting at 0.

adjust :: (a -> a) -> Int -> LSeq n a -> LSeq n a Source #

\( O(log(min(i,n−i))) \) Update the element at the specified position. If the position is out of range, the original sequence is returned. adjust can lead to poor performance and even memory leaks, because it does not force the new value before installing it in the sequence. adjust' should usually be preferred.

partition :: (a -> Bool) -> LSeq n a -> (LSeq 0 a, LSeq 0 a) Source #

\( O(n) \) The partition function takes a predicate p and a sequence xs and returns sequences of those elements which do and do not satisfy the predicate.

mapWithIndex :: (Int -> a -> b) -> LSeq n a -> LSeq n b Source #

A generalization of fmap, mapWithIndex takes a mapping function that also depends on the element's index, and applies it to every element in the sequence.

take :: Int -> LSeq n a -> LSeq 0 a Source #

\( O(\log(\min(i,n-i))) \). The first i elements of a sequence. If i is negative, take i s yields the empty sequence. If the sequence contains fewer than i elements, the whole sequence is returned.

drop :: Int -> LSeq n a -> LSeq 0 a Source #

\( O(\log(\min(i,n-i))) \). Elements of a sequence after the first i. If i is negative, drop i s yields the whole sequence. If the sequence contains fewer than i elements, the empty sequence is returned.

unstableSort :: Ord a => LSeq n a -> LSeq n a Source #

\( O(n \log n) \). unstableSort sorts the specified LSeq by the natural ordering of its elements, but the sort is not stable. This algorithm is frequently faster and uses less memory than sort.

unstableSortBy :: (a -> a -> Ordering) -> LSeq n a -> LSeq n a Source #

\( O(n \log n) \). A generalization of unstableSort, unstableSortBy takes an arbitrary comparator and sorts the specified sequence. The sort is not stable. This algorithm is frequently faster and uses less memory than sortBy.

head :: LSeq (1 + n) a -> a Source #

Gets the first element of the LSeq

>>> head $ forceLSeq (Proxy :: Proxy 3) $ fromList [1,2,3]
1

tail :: LSeq (1 + n) a -> LSeq n a Source #

Get the LSeq without its first element -- >>> head $ forceLSeq (Proxy :: Proxy 3) $ fromList [1,2,3] LSeq (fromList [2,3])

last :: LSeq (1 + n) a -> a Source #

Get the last element of the LSeq

>>> last $ forceLSeq (Proxy :: Proxy 3) $ fromList [1,2,3]
3

init :: LSeq (1 + n) a -> LSeq n a Source #

The sequence without its last element

>>> init $ forceLSeq (Proxy :: Proxy 3) $ fromList [1,2,3]
LSeq (fromList [1,2])

append :: LSeq n a -> LSeq m a -> LSeq (n + m) a Source #

appends two sequences.

data ViewL n a where Source #

View of the left end of a sequence.

Constructors

(:<) :: a -> LSeq n a -> ViewL (1 + n) a infixr 5 

Instances

Instances details
Functor (ViewL n) Source # 
Instance details

Defined in Data.LSeq

Methods

fmap :: (a -> b) -> ViewL n a -> ViewL n b #

(<$) :: a -> ViewL n b -> ViewL n a #

Foldable (ViewL n) Source # 
Instance details

Defined in Data.LSeq

Methods

fold :: Monoid m => ViewL n m -> m #

foldMap :: Monoid m => (a -> m) -> ViewL n a -> m #

foldMap' :: Monoid m => (a -> m) -> ViewL n a -> m #

foldr :: (a -> b -> b) -> b -> ViewL n a -> b #

foldr' :: (a -> b -> b) -> b -> ViewL n a -> b #

foldl :: (b -> a -> b) -> b -> ViewL n a -> b #

foldl' :: (b -> a -> b) -> b -> ViewL n a -> b #

foldr1 :: (a -> a -> a) -> ViewL n a -> a #

foldl1 :: (a -> a -> a) -> ViewL n a -> a #

toList :: ViewL n a -> [a] #

null :: ViewL n a -> Bool #

length :: ViewL n a -> Int #

elem :: Eq a => a -> ViewL n a -> Bool #

maximum :: Ord a => ViewL n a -> a #

minimum :: Ord a => ViewL n a -> a #

sum :: Num a => ViewL n a -> a #

product :: Num a => ViewL n a -> a #

Traversable (ViewL n) Source # 
Instance details

Defined in Data.LSeq

Methods

traverse :: Applicative f => (a -> f b) -> ViewL n a -> f (ViewL n b) #

sequenceA :: Applicative f => ViewL n (f a) -> f (ViewL n a) #

mapM :: Monad m => (a -> m b) -> ViewL n a -> m (ViewL n b) #

sequence :: Monad m => ViewL n (m a) -> m (ViewL n a) #

1 <= n => Traversable1 (ViewL n) Source # 
Instance details

Defined in Data.LSeq

Methods

traverse1 :: Apply f => (a -> f b) -> ViewL n a -> f (ViewL n b) #

sequence1 :: Apply f => ViewL n (f b) -> f (ViewL n b) #

1 <= n => Foldable1 (ViewL n) Source # 
Instance details

Defined in Data.LSeq

Methods

fold1 :: Semigroup m => ViewL n m -> m #

foldMap1 :: Semigroup m => (a -> m) -> ViewL n a -> m #

toNonEmpty :: ViewL n a -> NonEmpty a #

Eq a => Eq (ViewL n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(==) :: ViewL n a -> ViewL n a -> Bool #

(/=) :: ViewL n a -> ViewL n a -> Bool #

Ord a => Ord (ViewL n a) Source # 
Instance details

Defined in Data.LSeq

Methods

compare :: ViewL n a -> ViewL n a -> Ordering #

(<) :: ViewL n a -> ViewL n a -> Bool #

(<=) :: ViewL n a -> ViewL n a -> Bool #

(>) :: ViewL n a -> ViewL n a -> Bool #

(>=) :: ViewL n a -> ViewL n a -> Bool #

max :: ViewL n a -> ViewL n a -> ViewL n a #

min :: ViewL n a -> ViewL n a -> ViewL n a #

Show a => Show (ViewL n a) Source # 
Instance details

Defined in Data.LSeq

Methods

showsPrec :: Int -> ViewL n a -> ShowS #

show :: ViewL n a -> String #

showList :: [ViewL n a] -> ShowS #

Semigroup (ViewL n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(<>) :: ViewL n a -> ViewL n a -> ViewL n a #

sconcat :: NonEmpty (ViewL n a) -> ViewL n a #

stimes :: Integral b => b -> ViewL n a -> ViewL n a #

viewl :: LSeq (1 + n) a -> ViewL (1 + n) a Source #

( O(1) ). Analyse the left end of a sequence.

data ViewR n a where Source #

View of the right end of a sequence.

Constructors

(:>) :: LSeq n a -> a -> ViewR (1 + n) a infixl 5 

Instances

Instances details
Functor (ViewR n) Source # 
Instance details

Defined in Data.LSeq

Methods

fmap :: (a -> b) -> ViewR n a -> ViewR n b #

(<$) :: a -> ViewR n b -> ViewR n a #

Foldable (ViewR n) Source # 
Instance details

Defined in Data.LSeq

Methods

fold :: Monoid m => ViewR n m -> m #

foldMap :: Monoid m => (a -> m) -> ViewR n a -> m #

foldMap' :: Monoid m => (a -> m) -> ViewR n a -> m #

foldr :: (a -> b -> b) -> b -> ViewR n a -> b #

foldr' :: (a -> b -> b) -> b -> ViewR n a -> b #

foldl :: (b -> a -> b) -> b -> ViewR n a -> b #

foldl' :: (b -> a -> b) -> b -> ViewR n a -> b #

foldr1 :: (a -> a -> a) -> ViewR n a -> a #

foldl1 :: (a -> a -> a) -> ViewR n a -> a #

toList :: ViewR n a -> [a] #

null :: ViewR n a -> Bool #

length :: ViewR n a -> Int #

elem :: Eq a => a -> ViewR n a -> Bool #

maximum :: Ord a => ViewR n a -> a #

minimum :: Ord a => ViewR n a -> a #

sum :: Num a => ViewR n a -> a #

product :: Num a => ViewR n a -> a #

Traversable (ViewR n) Source # 
Instance details

Defined in Data.LSeq

Methods

traverse :: Applicative f => (a -> f b) -> ViewR n a -> f (ViewR n b) #

sequenceA :: Applicative f => ViewR n (f a) -> f (ViewR n a) #

mapM :: Monad m => (a -> m b) -> ViewR n a -> m (ViewR n b) #

sequence :: Monad m => ViewR n (m a) -> m (ViewR n a) #

Eq a => Eq (ViewR n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(==) :: ViewR n a -> ViewR n a -> Bool #

(/=) :: ViewR n a -> ViewR n a -> Bool #

Ord a => Ord (ViewR n a) Source # 
Instance details

Defined in Data.LSeq

Methods

compare :: ViewR n a -> ViewR n a -> Ordering #

(<) :: ViewR n a -> ViewR n a -> Bool #

(<=) :: ViewR n a -> ViewR n a -> Bool #

(>) :: ViewR n a -> ViewR n a -> Bool #

(>=) :: ViewR n a -> ViewR n a -> Bool #

max :: ViewR n a -> ViewR n a -> ViewR n a #

min :: ViewR n a -> ViewR n a -> ViewR n a #

Show a => Show (ViewR n a) Source # 
Instance details

Defined in Data.LSeq

Methods

showsPrec :: Int -> ViewR n a -> ShowS #

show :: ViewR n a -> String #

showList :: [ViewR n a] -> ShowS #

Semigroup (ViewR n a) Source # 
Instance details

Defined in Data.LSeq

Methods

(<>) :: ViewR n a -> ViewR n a -> ViewR n a #

sconcat :: NonEmpty (ViewR n a) -> ViewR n a #

stimes :: Integral b => b -> ViewR n a -> ViewR n a #

viewr :: LSeq (1 + n) a -> ViewR (1 + n) a Source #

\( O(1) \). Analyse the right end of a sequence.

zipWith :: (a -> b -> c) -> LSeq n a -> LSeq n b -> LSeq n c Source #

Zips two equal length LSeqs

promise :: forall m n a. LSeq m a -> LSeq n a Source #

Promises that the length of this LSeq is actually n. This is not checked.

This function should be a noop

forceLSeq :: KnownNat n => proxy n -> LSeq m a -> LSeq n a Source #

Forces the first n elements of the LSeq