-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | List-like structures with static checks on the number of elements -- -- We provide a data type 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. -- -- The package uses Haskell 98. -- -- Similar packages: -- -- -- -- Related packages: -- -- @package non-empty @version 0.0 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 class 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 Sort f sortBy :: Sort f => (a -> a -> Ordering) -> f a -> f a insertBy :: Sort f => (a -> a -> Ordering) -> a -> f a -> (a, f a) sort :: (Ord a, Sort f) => f a -> 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, Sort f) => a -> f a -> (a, f a) class Arbitrary f arbitrary :: (Arbitrary f, Arbitrary a) => Gen (f a) shrink :: (Arbitrary f, Arbitrary a) => f a -> [f a] instance Arbitrary [] instance Sort Maybe instance Sort [] instance Zip Maybe instance Zip [] instance Append [] instance Singleton Maybe instance Singleton [] instance View Maybe instance View [] instance Cons [] instance Empty Maybe instance Empty [] module Data.NonEmpty -- | The type T can be used for many kinds of list-like structures -- with restrictions on the size. -- -- 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 data Empty a Empty :: Empty a 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 :: (Foldable f, Cons f, Empty 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 -- | minimum is a total function minimum :: (Ord a, Foldable f) => 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 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 -- | 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 => (a -> a -> Ordering) -> T f a -> T f a sort :: (Ord a, Sort f) => T f a -> T f a insertBy :: (Sort f, Cons f) => (a -> a -> Ordering) -> a -> T f a -> T f a insert :: (Ord a, Sort f, Cons f) => a -> T f a -> T f a -- | Functions that cope both with plain and non-empty structures. module Data.NonEmpty.Mixed groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [T [] a] segmentBefore :: Foldable f => (a -> Bool) -> f a -> ([a], [T [] a]) scanl :: (a -> b -> a) -> a -> [b] -> T [] a genericScanl :: Foldable f => (a -> b -> a) -> a -> f b -> T [] a insertBy :: Sort f => (a -> a -> Ordering) -> a -> f a -> T f a insert :: (Ord a, Sort f) => a -> f a -> T f a appendLeft :: (Append f, View f, Cons f) => f a -> T f a -> T f a tails :: (View f, Empty f) => f a -> T [] (f a) inits :: (View f, Cons f, Empty f) => f a -> T [] (f a) appendRight :: Append f => T f a -> f a -> T f a