-- 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.1 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 Maybe instance Reverse [] instance Sort Maybe instance Sort [] instance Repeat [] 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.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. -- -- 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