-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | List-like structures with static restrictions on the number of elements
--
-- We provide the data type NonEmpty that allows to store a
-- list-like structure with at least or exactly n elements,
-- where n is fixed in the type in a kind of Peano encoding and
-- is usually small. The datatype is intended to increase safety by
-- making functions total that are partial on plain lists. E.g. on a
-- non-empty list, head and tail are always defined.
--
-- There are more such data types like Optional and
-- Empty. Together with NonEmpty you can define a list
-- type for every finite set of admissible list lengths.
--
-- The datatype can be combined with Lists, Sequences and Sets (from the
-- containers package).
--
-- The package needs only Haskell 98.
--
-- Similar packages:
--
--
-- - semigroups, semigroupoids: restricted to lists,
-- minimum number of elements: 1, provides more type classes tailored to
-- the use of non-empty lists.
-- - NonEmptyList: restricted to lists, minimum number of
-- elements: 1
-- - NonEmpty: restricted to lists, minimum number of
-- elements: 1, designed for unqualified use of identifiers
-- - Cardinality:NeverEmptyList
-- - http://www.haskell.org/haskellwiki/Non-empty_list
--
--
-- Related packages:
--
--
-- - Stream: Lists that contain always infinitely many
-- elements.
-- - fixed-list: Uses the same data structure as this package
-- but is intended for fixing the number of elements in a list. Requires
-- multi-parameter type classes with functional dependencies.
--
@package non-empty
@version 0.1.2
module Data.NonEmpty.Class
class Empty f
empty :: Empty f => f a
class Cons f
cons :: Cons f => a -> f a -> f a
class View f
viewL :: View f => f a -> Maybe (a, f a)
class Singleton f
singleton :: Singleton f => a -> f a
class Append f
append :: Append f => f a -> f a -> f a
-- | It must hold:
--
--
-- fmap f xs
-- = zipWith (\x _ -> f x) xs xs
-- = zipWith (\_ x -> f x) xs xs
--
class Functor f => Zip f
zipWith :: Zip f => (a -> b -> c) -> f a -> f b -> f c
zip :: Zip f => f a -> f b -> f (a, b)
class Repeat f
repeat :: Repeat f => a -> f a
class Sort f
sortBy :: Sort f => (a -> a -> Ordering) -> f a -> f a
sort :: (Ord a, Sort f) => f a -> f a
class Reverse f
reverse :: Reverse f => f a -> f a
class Show f
showsPrec :: (Show f, Show a) => Int -> f a -> ShowS
class Arbitrary f
arbitrary :: (Arbitrary f, Arbitrary a) => Gen (f a)
shrink :: (Arbitrary f, Arbitrary a) => f a -> [f a]
instance Arbitrary []
instance Show []
instance Reverse Seq
instance Reverse Maybe
instance Reverse []
instance Sort Seq
instance Sort Maybe
instance Sort []
instance Repeat []
instance Zip Seq
instance Zip Maybe
instance Zip []
instance Append Seq
instance Append []
instance Singleton Seq
instance Singleton Set
instance Singleton Maybe
instance Singleton []
instance View Seq
instance View Set
instance View Maybe
instance View []
instance Cons Seq
instance Cons []
instance Empty Seq
instance Empty Set
instance Empty Maybe
instance Empty []
module Data.Empty
data T a
Cons :: T a
instance Eq (T a)
instance Ord (T a)
instance Sort T
instance Reverse T
instance Zip T
instance Empty T
instance Arbitrary (T a)
instance View T
instance Traversable T
instance Foldable T
instance Functor T
instance Show T
instance Show (T a)
module Data.NonEmpty
-- | The type T can be used for many kinds of list-like structures
-- with restrictions on the size.
--
--
-- - T [] a is a lazy list containing at least one
-- element.
-- - T (T []) a is a lazy list containing at least two
-- elements.
-- - T Vector a is a vector with at least one element. You may
-- also use unboxed vectors but the first element will be stored in a box
-- and you will not be able to use many functions from this module.
-- - T Maybe a is a list that contains one or two
-- elements.
-- - Maybe is isomorphic to Optional Empty.
-- - T Empty a is a list that contains exactly one
-- element.
-- - T (T Empty) a is a list that contains exactly two
-- elements.
-- - Optional (T Empty) a is a list that contains zero or two
-- elements.
-- - You can create a list type for every finite set of allowed list
-- length by nesting Optional and NonEmpty constructors. If list length
-- n is allowed, then place Optional at depth
-- n, if it is disallowed then place NonEmpty. The
-- maximm length is marked by Empty.
--
data T f a
Cons :: a -> f a -> T f a
head :: T f a -> a
tail :: T f a -> f a
(!:) :: a -> f a -> T f a
-- | Force immediate generation of Cons.
force :: T f a -> T f a
-- | Implementation of <*> without the Empty constraint
-- that is needed for pure.
apply :: (Applicative f, Cons f, Append f) => T f (a -> b) -> T f a -> T f b
-- | Implementation of >>= without the Empty constraint
-- that is needed for return.
bind :: (Monad f, Cons f, Append f) => T f a -> (a -> T f b) -> T f b
toList :: Foldable f => T f a -> [a]
flatten :: Cons f => T f a -> f a
fetch :: View f => f a -> Maybe (T f a)
cons :: Cons f => a -> T f a -> T f a
singleton :: Empty f => a -> T f a
reverse :: (Traversable f, Reverse f) => T f a -> T f a
mapHead :: (a -> a) -> T f a -> T f a
mapTail :: (f a -> g a) -> T f a -> T g a
init :: (Zip f, Cons f) => T f a -> f a
last :: Foldable f => T f a -> a
foldl1 :: Foldable f => (a -> a -> a) -> T f a -> a
-- | maximum is a total function
maximum :: (Ord a, Foldable f) => T f a -> a
-- | maximumBy is a total function
maximumBy :: Foldable f => (a -> a -> Ordering) -> T f a -> a
-- | maximumKey is a total function
maximumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> a
-- | minimum is a total function
minimum :: (Ord a, Foldable f) => T f a -> a
-- | minimumBy is a total function
minimumBy :: Foldable f => (a -> a -> Ordering) -> T f a -> a
-- | minimumKey is a total function
minimumKey :: (Ord b, Foldable f) => (a -> b) -> T f a -> a
-- | sum does not need a zero for initialization
sum :: (Num a, Foldable f) => T f a -> a
-- | product does not need a one for initialization
product :: (Num a, Foldable f) => T f a -> a
append :: (Cons f, Append f) => T f a -> T f a -> T f a
appendLeft :: (Append f, View f, Cons f) => f a -> T f a -> T f a
appendRight :: Append f => T f a -> f a -> T f a
-- | generic variants: cycle or better Semigroup.cycle
cycle :: (Cons f, Append f) => T f a -> T f a
zipWith :: Zip f => (a -> b -> c) -> T f a -> T f b -> T f c
mapAdjacent :: Traversable f => (a -> a -> b) -> T f a -> f b
-- | If you nest too many non-empty lists then the efficient merge-sort
-- (linear-logarithmic runtime) will degenerate to an inefficient
-- insert-sort (quadratic runtime).
sortBy :: (Sort f, Insert f) => (a -> a -> Ordering) -> T f a -> T f a
sort :: (Ord a, Sort f, Insert f) => T f a -> T f a
class Insert f
insertBy :: Insert f => (a -> a -> Ordering) -> a -> f a -> T f a
-- | Insert an element into an ordered list while preserving the order. The
-- first element of the resulting list is returned individually. We need
-- this for construction of a non-empty list.
insert :: (Ord a, Insert f, Sort f) => a -> f a -> T f a
scanl :: Traversable f => (b -> a -> b) -> b -> f a -> T f b
scanr :: Traversable f => (a -> b -> b) -> b -> f a -> T f b
-- | Always returns a rectangular list by clipping all dimensions to the
-- shortest slice. Be aware that transpose [] == repeat [].
transposeClip :: (Traversable f, Zip g, Repeat g) => f (g a) -> g (f a)
class Tails f
tails :: (Tails f, Cons g, Empty g) => f a -> T f (g a)
class Functor f => RemoveEach f
removeEach :: RemoveEach f => T f a -> T f (a, f a)
-- | Functions that cope both with plain and non-empty structures.
--
-- If there are two versions of a function, where one works on
-- fixed-length lists, the place the fixed-length list variant to
-- NonEmpty and the other one here.
module Data.NonEmpty.Mixed
groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [T [] a]
segmentBefore :: Foldable f => (a -> Bool) -> f a -> ([a], [T [] a])
mapAdjacent :: (Cons f, Zip f) => (a -> a -> b) -> T f a -> f b
tails :: (View f, Empty f) => f a -> T [] (f a)
inits :: (View f, Cons f, Empty f) => f a -> T [] (f a)
appendLeft :: Cons f => [a] -> f a -> f a
module Data.Optional
data T f a
Nil :: T f a
Cons :: a -> (f a) -> T f a
(?:) :: a -> f a -> T f a
fromEmpty :: T a -> T f a
fromNonEmpty :: T f a -> T f a
instance (Eq a, Eq (f a)) => Eq (T f a)
instance (Ord a, Ord (f a)) => Ord (T f a)
instance Tails f => Tails (T f)
instance RemoveEach f => RemoveEach (T f)
instance Insert f => Insert (T f)
instance (Insert f, Sort f) => Sort (T f)
instance (Traversable f, Reverse f) => Reverse (T f)
instance Zip f => Zip (T f)
instance Repeat f => Repeat (T f)
instance (Cons f, Empty f) => Cons (T f)
instance Empty (T f)
instance (Arbitrary f, Arbitrary a) => Arbitrary (T f a)
instance Traversable f => Traversable (T f)
instance Foldable f => Foldable (T f)
instance Functor f => Functor (T f)
instance Show f => Show (T f)
instance (Show f, Show a) => Show (T f a)