-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell 98 semigroups -- -- Haskell 98 semigroups -- -- In mathematics, a semigroup is an algebraic structure consisting of a -- set together with an associative binary operation. A semigroup -- generalizes a monoid in that there might not exist an identity -- element. It also (originally) generalized a group (a monoid with all -- inverses) to a type where every element did not have to have an -- inverse, thus the name semigroup. @package semigroups @version 0.8.5 -- | This module exposes the potentially unsafe operations that are -- sometimes needed for efficiency: The Natural data constructor and -- unsafePred. module Numeric.Natural.Internal newtype Natural Natural :: Integer -> Natural runNatural :: Natural -> Integer -- | A refinement of Integral to represent types that do not contain -- negative numbers. class Integral n => Whole n toNatural :: Whole n => n -> Natural unsafePred :: Whole n => n -> n instance Eq Natural instance Ord Natural instance Ix Natural instance Whole Natural instance Whole Word64 instance Whole Word32 instance Whole Word16 instance Whole Word8 instance Whole Word instance Integral Natural instance Enum Natural instance Real Natural instance Bits Natural instance Num Natural instance Read Natural instance Show Natural -- | Natural numbers. module Numeric.Natural data Natural -- | A refinement of Integral to represent types that do not contain -- negative numbers. class Integral n => Whole n toNatural :: Whole n => n -> Natural -- | A NonEmpty list forms a monad as per list, but always contains at -- least one element. module Data.List.NonEmpty data NonEmpty a (:|) :: a -> [a] -> NonEmpty a -- | Map a function over a NonEmpty stream. map :: (a -> b) -> NonEmpty a -> NonEmpty b -- | 'intersperse x xs' alternates elements of the list with copies of -- x. -- --
-- intersperse 0 (1 :| [2,3]) == 1 :| [0,2,0,3] --intersperse :: a -> NonEmpty a -> NonEmpty a -- | scanl is similar to foldl, but returns a stream of -- successive reduced values from the left: -- --
-- scanl f z [x1, x2, ...] == z :| [z `f` x1, (z `f` x1) `f` x2, ...] ---- -- Note that -- --
-- last (scanl f z xs) == foldl f z xs. --scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b -- | scanr is the right-to-left dual of scanl. Note that -- --
-- head (scanr f z xs) == foldr f z xs. --scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b -- | scanl1 is a variant of scanl that has no starting value -- argument: -- --
-- scanl1 f [x1, x2, ...] == x1 :| [x1 `f` x2, x1 `f` (x2 `f` x3), ...] --scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a -- | scanr1 is a variant of scanr that has no starting value -- argument. scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a -- | Extract the first element of the stream. head :: NonEmpty a -> a -- | Extract the possibly-empty tail of the stream. tail :: NonEmpty a -> [a] -- | Extract the last element of the stream. last :: NonEmpty a -> a -- | Extract everything except the last element of the stream. init :: NonEmpty a -> [a] -- | Prepend an element to the stream. (<|) :: a -> NonEmpty a -> NonEmpty a -- | Synonym for <|. cons :: a -> NonEmpty a -> NonEmpty a -- | uncons produces the first element of the stream, and a stream -- of the remaining elements, if any. uncons :: NonEmpty a -> (a, Maybe (NonEmpty a)) -- | Sort a stream. sort :: Ord a => NonEmpty a -> NonEmpty a -- | reverse a finite NonEmpty stream. reverse :: NonEmpty a -> NonEmpty a -- | The inits function takes a stream xs and returns all -- the finite prefixes of xs. inits :: Foldable f => f a -> NonEmpty [a] -- | The tails function takes a stream xs and returns all -- the suffixes of xs. tails :: Foldable f => f a -> NonEmpty [a] -- | iterate f x produces the infinite sequence of repeated -- applications of f to x. -- --
-- iterate f x = x :| [f x, f (f x), ..] --iterate :: (a -> a) -> a -> NonEmpty a -- | repeat x returns a constant stream, where all elements -- are equal to x. repeat :: a -> NonEmpty a -- | cycle xs returns the infinite repetition of -- xs: -- --
-- cycle [1,2,3] = 1 :| [2,3,1,2,3,...] --cycle :: NonEmpty a -> NonEmpty a -- | unfold produces a new stream by repeatedly applying the -- unfolding function to the seed value to produce an element of type -- b and a new seed value. When the unfolding function returns -- Nothing instead of a new seed value, the stream ends. unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b -- | insert x xs inserts x into the last position -- in xs where it is still less than or equal to the next -- element. In particular, if the list is sorted beforehand, the result -- will also be sorted. insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a -- | take n xs returns the first n elements of -- xs. take :: Int -> NonEmpty a -> [a] -- | drop n xs drops the first n elements off the -- front of the sequence xs. drop :: Int -> NonEmpty a -> [a] -- | splitAt n xs returns a pair consisting of the prefix -- of xs of length n and the remaining stream -- immediately following this prefix. -- --
-- 'splitAt' n xs == ('take' n xs, 'drop' n xs)
-- xs == ys ++ zs where (ys, zs) = 'splitAt' n xs
--
splitAt :: Int -> NonEmpty a -> ([a], [a])
-- | takeWhile p xs returns the longest prefix of the
-- stream xs for which the predicate p holds.
takeWhile :: (a -> Bool) -> NonEmpty a -> [a]
-- | dropWhile p xs returns the suffix remaining after
-- takeWhile p xs.
dropWhile :: (a -> Bool) -> NonEmpty a -> [a]
-- | span p xs returns the longest prefix of xs
-- that satisfies p, together with the remainder of the stream.
--
--
-- 'span' p xs == ('takeWhile' p xs, 'dropWhile' p xs)
-- xs == ys ++ zs where (ys, zs) = 'span' p xs
--
span :: (a -> Bool) -> NonEmpty a -> ([a], [a])
-- | The break p function is equivalent to span
-- (not . p).
break :: (a -> Bool) -> NonEmpty a -> ([a], [a])
-- | filter p xs removes any elements from xs that
-- do not satisfy p.
filter :: (a -> Bool) -> NonEmpty a -> [a]
-- | The partition function takes a predicate p and a
-- stream xs, and returns a pair of lists. The first list
-- corresponds to the elements of xs for which p holds;
-- the second corresponds to the elements of xs for which
-- p does not hold.
--
--
-- 'partition' p xs = ('filter' p xs, 'filter' (not . p) xs)
--
partition :: (a -> Bool) -> NonEmpty a -> ([a], [a])
-- | The group function takes a stream and returns a list of streams
-- such that flattening the resulting list is equal to the argument.
-- Moreover, each stream in the resulting list contains only equal
-- elements. For example, in list notation:
--
-- -- 'group' $ 'cycle' "Mississippi" = "M" : "i" : "ss" : "i" : "ss" : "i" : "pp" : "i" : "M" : "i" : ... --group :: (Foldable f, Eq a) => f a -> [NonEmpty a] -- | groupBy operates like group, but uses the provided -- equality predicate instead of ==. groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a] -- | group1 operates like group, but uses the knowledge that -- its input is non-empty to produce guaranteed non-empty output. group1 :: Eq a => NonEmpty a -> NonEmpty (NonEmpty a) -- | groupBy1 is to group1 as groupBy is to -- group. groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | The isPrefix function returns True if the first -- argument is a prefix of the second. isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool -- | xs !! n returns the element of the stream xs at -- index n. Note that the head of the stream has index 0. -- -- Beware: a negative or out-of-bounds index will cause an error. (!!) :: NonEmpty a -> Int -> a -- | The zip function takes two streams and returns a stream of -- corresponding pairs. zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b) -- | The zipWith function generalizes zip. Rather than -- tupling the elements, the elements are combined using the function -- passed as the first argument. zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c -- | The unzip function is the inverse of the zip function. unzip :: Functor f => f (a, b) -> (f a, f b) -- | The words function breaks a stream of characters into a stream -- of words, which were delimited by white space. -- -- Beware: if the input contains no words (i.e. is entirely -- whitespace), this will cause an error. words :: NonEmpty Char -> NonEmpty String -- | The unwords function is an inverse operation to words. -- It joins words with separating spaces. -- -- Beware: the input ("" :| []) will cause an error. unwords :: NonEmpty String -> NonEmpty Char -- | The lines function breaks a stream of characters into a stream -- of strings at newline characters. The resulting strings do not contain -- newlines. lines :: NonEmpty Char -> NonEmpty String -- | The unlines function is an inverse operation to lines. -- It joins lines, after appending a terminating newline to each. unlines :: NonEmpty String -> NonEmpty Char -- | Converts a normal list to a NonEmpty stream. -- -- Raises an error if given an empty list. fromList :: [a] -> NonEmpty a -- | Convert a stream to a normal list efficiently. toList :: NonEmpty a -> [a] -- | nonEmpty efficiently turns a normal list into a NonEmpty -- stream, producing Nothing if the input is empty. nonEmpty :: [a] -> Maybe (NonEmpty a) xor :: NonEmpty Bool -> Bool instance Typeable1 NonEmpty instance Eq a => Eq (NonEmpty a) instance Ord a => Ord (NonEmpty a) instance Show a => Show (NonEmpty a) instance Read a => Read (NonEmpty a) instance Data a => Data (NonEmpty a) instance Foldable NonEmpty instance Traversable NonEmpty instance Monad NonEmpty instance Applicative NonEmpty instance Functor NonEmpty -- | In mathematics, a semigroup is an algebraic structure consisting of a -- set together with an associative binary operation. A semigroup -- generalizes a monoid in that there might not exist an identity -- element. It also (originally) generalized a group (a monoid with all -- inverses) to a type where every element did not have to have an -- inverse, thus the name semigroup. -- -- The use of (<>) in this module conflicts with an -- operator with the same name that is being exported by Data.Monoid. -- However, this package re-exports (most of) the contents of -- Data.Monoid, so to use semigroups and monoids in the same package just -- --
-- import Data.Semigroup --module Data.Semigroup class Semigroup a where sconcat (a :| as) = go a as where go b (c : cs) = b <> go c cs go b [] = b times1p y0 x0 = f x0 (1 + y0) where f x y | even y = f (x <> x) (y `quot` 2) | y == 1 = x | otherwise = g (x <> x) (unsafePred y `quot` 2) x g x y z | even y = g (x <> x) (y `quot` 2) z | y == 1 = x <> z | otherwise = g (x <> x) (unsafePred y `quot` 2) (x <> z) (<>) :: Semigroup a => a -> a -> a sconcat :: Semigroup a => NonEmpty a -> a times1p :: (Semigroup a, Whole n) => n -> a -> a newtype Min a Min :: a -> Min a getMin :: Min a -> a newtype Max a Max :: a -> Max a getMax :: Max a -> a -- | Use Option (First a) -- to get the behavior of -- First newtype First a First :: a -> First a getFirst :: First a -> a -- | Use Option (Last a) -- to get the behavior of -- Last newtype Last a Last :: a -> Last a getLast :: Last a -> a -- | Provide a Semigroup for an arbitrary Monoid. newtype WrappedMonoid m WrapMonoid :: m -> WrappedMonoid m unwrapMonoid :: WrappedMonoid m -> m -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following laws: -- --
mappend mempty x = x
mappend x mempty = x
mappend x (mappend y z) = mappend (mappend x y) z
mconcat = foldr mappend mempty