-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A compatibility layer for base -- -- Provides functions available in later versions of base to a -- wider range of compilers, without requiring you to use CPP pragmas in -- your code. See the README for what is covered. Also see the -- changelog for recent changes. -- -- Note that base-compat does not add any orphan instances. -- There is a separate package, base-orphans, for that. -- -- In addition, base-compat does not backport any data types or -- type classes. See this section of the README for more -- info. -- -- base-compat is designed to have zero dependencies. For a -- version of base-compat that depends on compatibility -- libraries for a wider support window, see the -- base-compat-batteries package. Most of the modules in -- this library have the same names as in base-compat-batteries -- to make it easier to switch between the two. There also exist versions -- of each module with the suffix .Repl, which are distinct from -- anything in base-compat-batteries, to allow for easier use in -- GHCi. @package base-compat @version 0.14.1 module Control.Concurrent.Compat -- | Fork a thread and call the supplied function when the thread is about -- to terminate, with an exception or a returned value. The function is -- called with asynchronous exceptions masked. -- --
--   forkFinally action and_then =
--     mask $ \restore ->
--       forkIO $ try (restore action) >>= and_then
--   
-- -- This function is useful for informing the parent when a child -- terminates, for example. forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId -- | Like forkIOWithUnmask, but the child thread is a bound thread, -- as with forkOS. forkOSWithUnmask :: ((forall a. () => IO a -> IO a) -> IO ()) -> IO ThreadId -- | Reexports Control.Concurrent.Compat from a globally unique -- namespace. module Control.Concurrent.Compat.Repl module Control.Concurrent.MVar.Compat -- | Like withMVar, but the IO action in the second -- argument is executed with asynchronous exceptions masked. withMVarMasked :: MVar a -> (a -> IO b) -> IO b -- | Reexports Control.Concurrent.MVar.Compat from a globally unique -- namespace. module Control.Concurrent.MVar.Compat.Repl module Control.Exception.Compat -- | Throw an exception. Exceptions may be thrown from purely functional -- code, but may only be caught within the IO monad. -- -- WARNING: You may want to use throwIO instead so that your -- pure code stays exception-free. throw :: forall (r :: RuntimeRep) (a :: TYPE r) e. Exception e => e -> a -- | Reexports Control.Exception.Compat from a globally unique -- namespace. module Control.Exception.Compat.Repl module Control.Monad.Compat -- | Monads that also support choice and failure. class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) -- | The identity of mplus. It should also satisfy the equations -- --
--   mzero >>= f  =  mzero
--   v >> mzero   =  mzero
--   
-- -- The default definition is -- --
--   mzero = empty
--   
mzero :: MonadPlus m => m a -- | An associative operation. The default definition is -- --
--   mplus = (<|>)
--   
mplus :: MonadPlus m => m a -> m a -> m a -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: Type -> Type) -- | Sequentially compose two actions, passing any value produced by the -- first as an argument to the second. -- -- 'as >>= bs' can be understood as the do -- expression -- --
--   do a <- as
--      bs a
--   
(>>=) :: Monad m => m a -> (a -> m b) -> m b -- | Sequentially compose two actions, discarding any value produced by the -- first, like sequencing operators (such as the semicolon) in imperative -- languages. -- -- 'as >> bs' can be understood as the do -- expression -- --
--   do as
--      bs
--   
(>>) :: Monad m => m a -> m b -> m b -- | Inject a value into the monadic type. return :: Monad m => a -> m a infixl 1 >>= infixl 1 >> -- | A type f is a Functor if it provides a function fmap -- which, given any types a and b lets you apply any -- function from (a -> b) to turn an f a into an -- f b, preserving the structure of f. Furthermore -- f needs to adhere to the following: -- -- -- -- Note, that the second law follows from the free theorem of the type -- fmap and the first law, so you need only check that the former -- condition holds. See -- https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or -- https://github.com/quchen/articles/blob/master/second_functor_law.md -- for an explanation. class () => Functor (f :: Type -> Type) -- | fmap is used to apply a function of type (a -> b) -- to a value of type f a, where f is a functor, to produce a -- value of type f b. Note that for any type constructor with -- more than one parameter (e.g., Either), only the last type -- parameter can be modified with fmap (e.g., b in -- `Either a b`). -- -- Some type constructors with two parameters or more have a -- Bifunctor instance that allows both the last and the -- penultimate parameters to be mapped over. -- --

Examples

-- -- Convert from a Maybe Int to a Maybe String -- using show: -- --
--   >>> fmap show Nothing
--   Nothing
--   
--   >>> fmap show (Just 3)
--   Just "3"
--   
-- -- Convert from an Either Int Int to an Either Int -- String using show: -- --
--   >>> fmap show (Left 17)
--   Left 17
--   
--   >>> fmap show (Right 17)
--   Right "17"
--   
-- -- Double each element of a list: -- --
--   >>> fmap (*2) [1,2,3]
--   [2,4,6]
--   
-- -- Apply even to the second element of a pair: -- --
--   >>> fmap even (2,2)
--   (2,True)
--   
-- -- It may seem surprising that the function is only applied to the last -- element of the tuple compared to the list example above which applies -- it to every element in the list. To understand, remember that tuples -- are type constructors with multiple type parameters: a tuple of 3 -- elements (a,b,c) can also be written (,,) a b c and -- its Functor instance is defined for Functor ((,,) a -- b) (i.e., only the third parameter is free to be mapped over with -- fmap). -- -- It explains why fmap can be used with tuples containing -- values of different types as in the following example: -- --
--   >>> fmap even ("hello", 1.0, 4)
--   ("hello",1.0,True)
--   
fmap :: Functor f => (a -> b) -> f a -> f b -- | Replace all locations in the input with the same value. The default -- definition is fmap . const, but this may be -- overridden with a more efficient version. -- --

Examples

-- -- Perform a computation with Maybe and replace the result with a -- constant value if it is Just: -- --
--   >>> 'a' <$ Just 2
--   Just 'a'
--   
--   >>> 'a' <$ Nothing
--   Nothing
--   
(<$) :: Functor f => a -> f b -> f a infixl 4 <$ -- | When a value is bound in do-notation, the pattern on the left -- hand side of <- might not match. In this case, this class -- provides a function to recover. -- -- A Monad without a MonadFail instance may only be used in -- conjunction with pattern that always match, such as newtypes, tuples, -- data types with only a single data constructor, and irrefutable -- patterns (~pat). -- -- Instances of MonadFail should satisfy the following law: -- fail s should be a left zero for >>=, -- --
--   fail s >>= f  =  fail s
--   
-- -- If your Monad is also MonadPlus, a popular definition is -- --
--   fail _ = mzero
--   
-- -- fail s should be an action that runs in the monad itself, not -- an exception (except in instances of MonadIO). In particular, -- fail should not be implemented in terms of error. class Monad m => MonadFail (m :: Type -> Type) fail :: MonadFail m => String -> m a -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and collect the results. For a version -- that ignores the results see mapM_. -- --

Examples

-- -- mapM is literally a traverse with a type signature -- restricted to Monad. Its implementation may be more efficient -- due to additional power of Monad. mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) -- | Evaluate each monadic action in the structure from left to right, and -- collect the results. For a version that ignores the results see -- sequence_. -- --

Examples

-- -- Basic usage: -- -- The first two examples are instances where the input and and output of -- sequence are isomorphic. -- --
--   >>> sequence $ Right [1,2,3,4]
--   [Right 1,Right 2,Right 3,Right 4]
--   
-- --
--   >>> sequence $ [Right 1,Right 2,Right 3,Right 4]
--   Right [1,2,3,4]
--   
-- -- The following examples demonstrate short circuit behavior for -- sequence. -- --
--   >>> sequence $ Left [1,2,3,4]
--   Left [1,2,3,4]
--   
-- --
--   >>> sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
--   Left 0
--   
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) -- | forM is mapM with its arguments flipped. For a version -- that ignores the results see forM_. forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) -- | Repeat an action indefinitely. -- --

Examples

-- -- A common use of forever is to process input from network -- sockets, Handles, and channels (e.g. MVar and -- Chan). -- -- For example, here is how we might implement an echo server, -- using forever both to listen for client connections on a -- network socket and to echo client input on client connection handles: -- --
--   echoServer :: Socket -> IO ()
--   echoServer socket = forever $ do
--     client <- accept socket
--     forkFinally (echo client) (\_ -> hClose client)
--     where
--       echo :: Handle -> IO ()
--       echo client = forever $
--         hGetLine client >>= hPutStrLn client
--   
-- -- Note that "forever" isn't necessarily non-terminating. If the action -- is in a MonadPlus and short-circuits after some number -- of iterations. then forever actually returns -- mzero, effectively short-circuiting its caller. forever :: Applicative f => f a -> f b -- | Promote a function to a monad. liftM :: Monad m => (a1 -> r) -> m a1 -> m r -- | Conditional failure of Alternative computations. Defined by -- --
--   guard True  = pure ()
--   guard False = empty
--   
-- --

Examples

-- -- Common uses of guard include conditionally signaling an error -- in an error monad and conditionally rejecting the current choice in an -- Alternative-based parser. -- -- As an example of signaling an error in the error monad Maybe, -- consider a safe division function safeDiv x y that returns -- Nothing when the denominator y is zero and -- Just (x `div` y) otherwise. For example: -- --
--   >>> safeDiv 4 0
--   Nothing
--   
-- --
--   >>> safeDiv 4 2
--   Just 2
--   
-- -- A definition of safeDiv using guards, but not guard: -- --
--   safeDiv :: Int -> Int -> Maybe Int
--   safeDiv x y | y /= 0    = Just (x `div` y)
--               | otherwise = Nothing
--   
-- -- A definition of safeDiv using guard and Monad -- do-notation: -- --
--   safeDiv :: Int -> Int -> Maybe Int
--   safeDiv x y = do
--     guard (y /= 0)
--     return (x `div` y)
--   
guard :: Alternative f => Bool -> f () -- | The join function is the conventional monad join operator. It -- is used to remove one level of monadic structure, projecting its bound -- argument into the outer level. -- -- 'join bss' can be understood as the do -- expression -- --
--   do bs <- bss
--      bs
--   
-- --

Examples

-- -- A common use of join is to run an IO computation -- returned from an STM transaction, since STM transactions -- can't perform IO directly. Recall that -- --
--   atomically :: STM a -> IO a
--   
-- -- is used to run STM transactions atomically. So, by specializing -- the types of atomically and join to -- --
--   atomically :: STM (IO b) -> IO (IO b)
--   join       :: IO (IO b)  -> IO b
--   
-- -- we can compose them as -- --
--   join . atomically :: STM (IO b) -> IO b
--   
-- -- to run an STM transaction and the IO action it returns. join :: Monad m => m (m a) -> m a -- | Same as >>=, but with the arguments interchanged. (=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 =<< -- | Conditional execution of Applicative expressions. For example, -- --
--   when debug (putStrLn "Debugging")
--   
-- -- will output the string Debugging if the Boolean value -- debug is True, and otherwise do nothing. when :: Applicative f => Bool -> f () -> f () -- | Promote a function to a monad, scanning the monadic arguments from -- left to right. For example, -- --
--   liftM2 (+) [0,1] [0,2] = [0,2,1,3]
--   liftM2 (+) (Just 1) Nothing = Nothing
--   
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r -- | In many situations, the liftM operations can be replaced by -- uses of ap, which promotes function application. -- --
--   return f `ap` x1 `ap` ... `ap` xn
--   
-- -- is equivalent to -- --
--   liftMn f x1 x2 ... xn
--   
ap :: Monad m => m (a -> b) -> m a -> m b -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --

Examples

-- -- Replace the contents of a Maybe Int with unit: -- --
--   >>> void Nothing
--   Nothing
--   
--   >>> void (Just 3)
--   Just ()
--   
-- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int (): -- --
--   >>> void (Left 8675309)
--   Left 8675309
--   
--   >>> void (Right 8675309)
--   Right ()
--   
-- -- Replace every element of a list with unit: -- --
--   >>> void [1,2,3]
--   [(),(),()]
--   
-- -- Replace the second element of a pair with unit: -- --
--   >>> void (1,2)
--   (1,())
--   
-- -- Discard the result of an IO action: -- --
--   >>> mapM print [1,2]
--   1
--   2
--   [(),()]
--   
--   >>> void $ mapM print [1,2]
--   1
--   2
--   
void :: Functor f => f a -> f () -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. For a version that -- doesn't ignore the results see mapM. -- -- mapM_ is just like traverse_, but specialised to monadic -- actions. mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m () -- | forM_ is mapM_ with its arguments flipped. For a version -- that doesn't ignore the results see forM. -- -- forM_ is just like for_, but specialised to monadic -- actions. forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () -- | Evaluate each monadic action in the structure from left to right, and -- ignore the results. For a version that doesn't ignore the results see -- sequence. -- -- sequence_ is just like sequenceA_, but specialised to -- monadic actions. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () -- | The sum of a collection of actions using (<|>), -- generalizing concat. -- -- msum is just like asum, but specialised to -- MonadPlus. -- --

Examples

-- -- Basic usage, using the MonadPlus instance for Maybe: -- --
--   >>> msum [Just "Hello", Nothing, Just "World"]
--   Just "Hello"
--   
msum :: (Foldable t, MonadPlus m) => t (m a) -> m a -- | This generalizes the list-based filter function. filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] -- | Left-to-right composition of Kleisli arrows. -- -- '(bs >=> cs) a' can be understood as the -- do expression -- --
--   do b <- bs a
--      cs b
--   
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 >=> -- | Right-to-left composition of Kleisli arrows. -- (>=>), with the arguments flipped. -- -- Note how this operator resembles function composition -- (.): -- --
--   (.)   ::            (b ->   c) -> (a ->   b) -> a ->   c
--   (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
--   
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c infixr 1 <=< -- | The mapAndUnzipM function maps its first argument over a list, -- returning the result as a pair of lists. This function is mainly used -- with complicated data structures or a state monad. mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) -- | The zipWithM function generalizes zipWith to arbitrary -- applicative functors. zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] -- | zipWithM_ is the extension of zipWithM which ignores the -- final result. zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () -- | The foldM function is analogous to foldl, except that -- its result is encapsulated in a monad. Note that foldM works -- from left-to-right over the list arguments. This could be an issue -- where (>>) and the `folded function' are not -- commutative. -- --
--   foldM f a1 [x1, x2, ..., xm]
--   
--   ==
--   
--   do
--     a2 <- f a1 x1
--     a3 <- f a2 x2
--     ...
--     f am xm
--   
-- -- If right-to-left evaluation is required, the input list should be -- reversed. -- -- Note: foldM is the same as foldlM foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b -- | Like foldM, but discards the result. foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () -- | replicateM n act performs the action act -- n times, and then returns the list of results: -- --

Examples

-- --
--   >>> import Control.Monad.State
--   
--   >>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1
--   ([1,2,3],4)
--   
replicateM :: Applicative m => Int -> m a -> m [a] -- | Like replicateM, but discards the result. -- --

Examples

-- --
--   >>> replicateM_ 3 (putStrLn "a")
--   a
--   a
--   a
--   
replicateM_ :: Applicative m => Int -> m a -> m () -- | The reverse of when. unless :: Applicative f => Bool -> f () -> f () -- | Strict version of <$>. (<$!>) :: Monad m => (a -> b) -> m a -> m b infixl 4 <$!> -- | Direct MonadPlus equivalent of filter. -- --

Examples

-- -- The filter function is just mfilter specialized to the -- list monad: -- --
--   filter = ( mfilter :: (a -> Bool) -> [a] -> [a] )
--   
-- -- An example using mfilter with the Maybe monad: -- --
--   >>> mfilter odd (Just 1)
--   Just 1
--   
--   >>> mfilter odd (Just 2)
--   Nothing
--   
mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: Type -> Type) -- | When a value is bound in do-notation, the pattern on the left -- hand side of <- might not match. In this case, this class -- provides a function to recover. -- -- A Monad without a MonadFail instance may only be used in -- conjunction with pattern that always match, such as newtypes, tuples, -- data types with only a single data constructor, and irrefutable -- patterns (~pat). -- -- Instances of MonadFail should satisfy the following law: -- fail s should be a left zero for >>=, -- --
--   fail s >>= f  =  fail s
--   
-- -- If your Monad is also MonadPlus, a popular definition is -- --
--   fail _ = mzero
--   
-- -- fail s should be an action that runs in the monad itself, not -- an exception (except in instances of MonadIO). In particular, -- fail should not be implemented in terms of error. class Monad m => MonadFail (m :: Type -> Type) fail :: MonadFail m => String -> m a -- | Monads that also support choice and failure. class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) -- | The identity of mplus. It should also satisfy the equations -- --
--   mzero >>= f  =  mzero
--   v >> mzero   =  mzero
--   
-- -- The default definition is -- --
--   mzero = empty
--   
mzero :: MonadPlus m => m a -- | An associative operation. The default definition is -- --
--   mplus = (<|>)
--   
mplus :: MonadPlus m => m a -> m a -> m a -- | Reexports Control.Monad.Compat from a globally unique -- namespace. module Control.Monad.Compat.Repl module Control.Monad.Fail.Compat -- | Reexports Control.Monad.Fail.Compat from a globally unique -- namespace. module Control.Monad.Fail.Compat.Repl module Control.Monad.IO.Class.Compat -- | Reexports Control.Monad.IO.Class.Compat from a globally unique -- namespace. module Control.Monad.IO.Class.Compat.Repl module Control.Monad.ST.Lazy.Unsafe.Compat unsafeInterleaveST :: ST s a -> ST s a unsafeIOToST :: IO a -> ST s a -- | Reexports Control.Monad.ST.Lazy.Unsafe.Compat from a globally -- unique namespace. module Control.Monad.ST.Lazy.Unsafe.Compat.Repl module Control.Monad.ST.Unsafe.Compat -- | unsafeInterleaveST allows an ST computation to be -- deferred lazily. When passed a value of type ST a, the -- ST computation will only be performed when the value of the -- a is demanded. unsafeInterleaveST :: ST s a -> ST s a -- | Convert an IO action to an ST action. This relies on -- IO and ST having the same representation modulo the -- constraint on the state thread type parameter. unsafeIOToST :: IO a -> ST s a -- | Convert an ST action to an IO action. This relies on -- IO and ST having the same representation modulo the -- constraint on the state thread type parameter. -- -- For an example demonstrating why this is unsafe, see -- https://mail.haskell.org/pipermail/haskell-cafe/2009-April/060719.html unsafeSTToIO :: ST s a -> IO a -- | Reexports Control.Monad.ST.Unsafe.Compat from a globally unique -- namespace. module Control.Monad.ST.Unsafe.Compat.Repl module Data.Bifoldable.Compat -- | Reexports Data.Bifoldable.Compat from a globally unique -- namespace. module Data.Bifoldable.Compat.Repl module Data.Bifoldable1.Compat -- | Reexports Data.Bifoldable1.Compat from a globally unique -- namespace. module Data.Bifoldable1.Compat.Repl module Data.Bifunctor.Compat -- | Reexports Data.Bifunctor.Compat from a globally unique -- namespace. module Data.Bifunctor.Compat.Repl module Data.Bits.Compat -- | Default implementation for bit. -- -- Note that: bitDefault i = 1 shiftL i bitDefault :: (Bits a, Num a) => Int -> a -- | Default implementation for testBit. -- -- Note that: testBitDefault x i = (x .&. bit i) /= 0 testBitDefault :: (Bits a, Num a) => a -> Int -> Bool -- | Default implementation for popCount. -- -- This implementation is intentionally naive. Instances are expected to -- provide an optimized implementation for their size. popCountDefault :: (Bits a, Num a) => a -> Int -- | Infix version of xor. (.^.) :: Bits a => a -> a -> a infixl 6 .^. -- | Infix version of shiftR. (.>>.) :: Bits a => a -> Int -> a infixl 8 .>>. -- | Infix version of shiftL. (.<<.) :: Bits a => a -> Int -> a infixl 8 .<<. -- | Infix version of unsafeShiftR. (!>>.) :: Bits a => a -> Int -> a infixl 8 !>>. -- | Infix version of unsafeShiftL. (!<<.) :: Bits a => a -> Int -> a infixl 8 !<<. -- | Attempt to convert an Integral type a to an -- Integral type b using the size of the types as -- measured by Bits methods. -- -- A simpler version of this function is: -- --
--   toIntegral :: (Integral a, Integral b) => a -> Maybe b
--   toIntegral x
--     | toInteger x == toInteger y = Just y
--     | otherwise                  = Nothing
--     where
--       y = fromIntegral x
--   
-- -- This version requires going through Integer, which can be -- inefficient. However, toIntegralSized is optimized to allow -- GHC to statically determine the relative type sizes (as measured by -- bitSizeMaybe and isSigned) and avoid going through -- Integer for many types. (The implementation uses -- fromIntegral, which is itself optimized with rules for -- base types but may go through Integer for some type -- pairs.) toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b -- | A more concise version of complement zeroBits. -- --
--   >>> complement (zeroBits :: Word) == (oneBits :: Word)
--   True
--   
-- --
--   >>> complement (oneBits :: Word) == (zeroBits :: Word)
--   True
--   
-- --

Note

-- -- The constraint on oneBits is arguably too strong. However, as -- some types (such as Natural) have undefined -- complement, this is the only safe choice. oneBits :: FiniteBits a => a -- | Reexports Data.Bits.Compat from a globally unique namespace. module Data.Bits.Compat.Repl module Data.Bool.Compat -- | Case analysis for the Bool type. bool x y p -- evaluates to x when p is False, and evaluates -- to y when p is True. -- -- This is equivalent to if p then y else x; that is, one can -- think of it as an if-then-else construct with its arguments reordered. -- --

Examples

-- -- Basic usage: -- --
--   >>> bool "foo" "bar" True
--   "bar"
--   
--   >>> bool "foo" "bar" False
--   "foo"
--   
-- -- Confirm that bool x y p and if p then y else -- x are equivalent: -- --
--   >>> let p = True; x = "bar"; y = "foo"
--   
--   >>> bool x y p == if p then y else x
--   True
--   
--   >>> let p = False
--   
--   >>> bool x y p == if p then y else x
--   True
--   
bool :: a -> a -> Bool -> a -- | Reexports Data.Bool.Compat from a globally unique namespace. module Data.Bool.Compat.Repl module Data.Complex.Compat -- | Reexports Data.Complex.Compat from a globally unique namespace. module Data.Complex.Compat.Repl module Data.Either.Compat -- | Return True if the given value is a Left-value, -- False otherwise. -- --

Examples

-- -- Basic usage: -- --
--   >>> isLeft (Left "foo")
--   True
--   
--   >>> isLeft (Right 3)
--   False
--   
-- -- Assuming a Left value signifies some sort of error, we can use -- isLeft to write a very simple error-reporting function that -- does absolutely nothing in the case of success, and outputs "ERROR" if -- any error occurred. -- -- This example shows how isLeft might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
--   >>> import Control.Monad ( when )
--   
--   >>> let report e = when (isLeft e) $ putStrLn "ERROR"
--   
--   >>> report (Right 1)
--   
--   >>> report (Left "parse error")
--   ERROR
--   
isLeft :: Either a b -> Bool -- | Return True if the given value is a Right-value, -- False otherwise. -- --

Examples

-- -- Basic usage: -- --
--   >>> isRight (Left "foo")
--   False
--   
--   >>> isRight (Right 3)
--   True
--   
-- -- Assuming a Left value signifies some sort of error, we can use -- isRight to write a very simple reporting function that only -- outputs "SUCCESS" when a computation has succeeded. -- -- This example shows how isRight might be used to avoid pattern -- matching when one does not care about the value contained in the -- constructor: -- --
--   >>> import Control.Monad ( when )
--   
--   >>> let report e = when (isRight e) $ putStrLn "SUCCESS"
--   
--   >>> report (Left "parse error")
--   
--   >>> report (Right 1)
--   SUCCESS
--   
isRight :: Either a b -> Bool -- | Return the contents of a Left-value or a default value -- otherwise. -- --

Examples

-- -- Basic usage: -- --
--   >>> fromLeft 1 (Left 3)
--   3
--   
--   >>> fromLeft 1 (Right "foo")
--   1
--   
fromLeft :: a -> Either a b -> a -- | Return the contents of a Right-value or a default value -- otherwise. -- --

Examples

-- -- Basic usage: -- --
--   >>> fromRight 1 (Right 3)
--   3
--   
--   >>> fromRight 1 (Left "foo")
--   1
--   
fromRight :: b -> Either a b -> b -- | Reexports Data.Either.Compat from a globally unique namespace. module Data.Either.Compat.Repl module Data.Foldable.Compat -- | Reexports Data.Foldable.Compat from a globally unique -- namespace. module Data.Foldable.Compat.Repl module Data.Foldable1.Compat -- | Reexports Data.Foldable1.Compat from a globally unique -- namespace. module Data.Foldable1.Compat.Repl module Data.Function.Compat -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
--   >>> 5 & (+1) & show
--   "6"
--   
(&) :: a -> (a -> b) -> b infixl 1 & -- | applyWhen applies a function to a value if a condition is true, -- otherwise, it returns the value unchanged. -- -- It is equivalent to flip (bool id). -- -- Algebraic properties: -- -- applyWhen :: Bool -> (a -> a) -> a -> a -- | Reexports Data.Function.Compat from a globally unique -- namespace. module Data.Function.Compat.Repl module Data.Functor.Compat -- | A type f is a Functor if it provides a function fmap -- which, given any types a and b lets you apply any -- function from (a -> b) to turn an f a into an -- f b, preserving the structure of f. Furthermore -- f needs to adhere to the following: -- -- -- -- Note, that the second law follows from the free theorem of the type -- fmap and the first law, so you need only check that the former -- condition holds. See -- https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or -- https://github.com/quchen/articles/blob/master/second_functor_law.md -- for an explanation. class () => Functor (f :: Type -> Type) -- | fmap is used to apply a function of type (a -> b) -- to a value of type f a, where f is a functor, to produce a -- value of type f b. Note that for any type constructor with -- more than one parameter (e.g., Either), only the last type -- parameter can be modified with fmap (e.g., b in -- `Either a b`). -- -- Some type constructors with two parameters or more have a -- Bifunctor instance that allows both the last and the -- penultimate parameters to be mapped over. -- --

Examples

-- -- Convert from a Maybe Int to a Maybe String -- using show: -- --
--   >>> fmap show Nothing
--   Nothing
--   
--   >>> fmap show (Just 3)
--   Just "3"
--   
-- -- Convert from an Either Int Int to an Either Int -- String using show: -- --
--   >>> fmap show (Left 17)
--   Left 17
--   
--   >>> fmap show (Right 17)
--   Right "17"
--   
-- -- Double each element of a list: -- --
--   >>> fmap (*2) [1,2,3]
--   [2,4,6]
--   
-- -- Apply even to the second element of a pair: -- --
--   >>> fmap even (2,2)
--   (2,True)
--   
-- -- It may seem surprising that the function is only applied to the last -- element of the tuple compared to the list example above which applies -- it to every element in the list. To understand, remember that tuples -- are type constructors with multiple type parameters: a tuple of 3 -- elements (a,b,c) can also be written (,,) a b c and -- its Functor instance is defined for Functor ((,,) a -- b) (i.e., only the third parameter is free to be mapped over with -- fmap). -- -- It explains why fmap can be used with tuples containing -- values of different types as in the following example: -- --
--   >>> fmap even ("hello", 1.0, 4)
--   ("hello",1.0,True)
--   
fmap :: Functor f => (a -> b) -> f a -> f b -- | Replace all locations in the input with the same value. The default -- definition is fmap . const, but this may be -- overridden with a more efficient version. -- --

Examples

-- -- Perform a computation with Maybe and replace the result with a -- constant value if it is Just: -- --
--   >>> 'a' <$ Just 2
--   Just 'a'
--   
--   >>> 'a' <$ Nothing
--   Nothing
--   
(<$) :: Functor f => a -> f b -> f a infixl 4 <$ -- | Flipped version of <$. -- --

Examples

-- -- Replace the contents of a Maybe Int with a -- constant String: -- --
--   >>> Nothing $> "foo"
--   Nothing
--   
--   >>> Just 90210 $> "foo"
--   Just "foo"
--   
-- -- Replace the contents of an Either Int -- Int with a constant String, resulting in an -- Either Int String: -- --
--   >>> Left 8675309 $> "foo"
--   Left 8675309
--   
--   >>> Right 8675309 $> "foo"
--   Right "foo"
--   
-- -- Replace each element of a list with a constant String: -- --
--   >>> [1,2,3] $> "foo"
--   ["foo","foo","foo"]
--   
-- -- Replace the second element of a pair with a constant String: -- --
--   >>> (1,2) $> "foo"
--   (1,"foo")
--   
($>) :: Functor f => f a -> b -> f b infixl 4 $> -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --

Examples

-- -- Replace the contents of a Maybe Int with unit: -- --
--   >>> void Nothing
--   Nothing
--   
--   >>> void (Just 3)
--   Just ()
--   
-- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int (): -- --
--   >>> void (Left 8675309)
--   Left 8675309
--   
--   >>> void (Right 8675309)
--   Right ()
--   
-- -- Replace every element of a list with unit: -- --
--   >>> void [1,2,3]
--   [(),(),()]
--   
-- -- Replace the second element of a pair with unit: -- --
--   >>> void (1,2)
--   (1,())
--   
-- -- Discard the result of an IO action: -- --
--   >>> mapM print [1,2]
--   1
--   2
--   [(),()]
--   
--   >>> void $ mapM print [1,2]
--   1
--   2
--   
void :: Functor f => f a -> f () -- | Flipped version of <$>. -- --
--   (<&>) = flip fmap
--   
-- --

Examples

-- -- Apply (+1) to a list, a Just and a Right: -- --
--   >>> Just 2 <&> (+1)
--   Just 3
--   
-- --
--   >>> [1,2,3] <&> (+1)
--   [2,3,4]
--   
-- --
--   >>> Right 3 <&> (+1)
--   Right 4
--   
(<&>) :: Functor f => f a -> (a -> b) -> f b infixl 1 <&> -- | Generalization of Data.List.unzip. -- -- Since: 4.19.0.0 unzip :: Functor f => f (a, b) -> (f a, f b) -- | Reexports Data.Functor.Compat from a globally unique namespace. module Data.Functor.Compat.Repl module Data.Functor.Compose.Compat -- | Reexports Data.Functor.Compose.Compat from a globally unique -- namespace. module Data.Functor.Compose.Compat.Repl module Data.Functor.Const.Compat -- | The Const functor. newtype () => Const a (b :: k) Const :: a -> Const a (b :: k) [getConst] :: Const a (b :: k) -> a -- | Reexports Data.Functor.Const.Compat from a globally unique -- namespace. module Data.Functor.Const.Compat.Repl module Data.Functor.Contravariant.Compat -- | Reexports Data.Functor.Contravariant.Compat from a globally -- unique namespace. module Data.Functor.Contravariant.Compat.Repl module Data.Functor.Identity.Compat -- | Reexports Data.Functor.Identity.Compat from a globally unique -- namespace. module Data.Functor.Identity.Compat.Repl module Data.Functor.Product.Compat -- | Reexports Data.Functor.Product.Compat from a globally unique -- namespace. module Data.Functor.Product.Compat.Repl module Data.Functor.Sum.Compat -- | Reexports Data.Functor.Sum.Compat from a globally unique -- namespace. module Data.Functor.Sum.Compat.Repl module Data.IORef.Compat -- | Strict version of modifyIORef. This is not an atomic update, -- consider using atomicModifyIORef' when operating in a -- multithreaded environment. modifyIORef' :: IORef a -> (a -> a) -> IO () -- | Strict version of atomicModifyIORef. This forces both the value -- stored in the IORef and the value returned. The new value is -- installed in the IORef before the returned value is forced. So -- --
--   atomicModifyIORef' ref (x -> (x+1, undefined))
--   
-- -- will increment the IORef and then throw an exception in the -- calling thread. -- -- This function imposes a memory barrier, preventing reordering; see -- Data.IORef#memmodel for details. atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b -- | Variant of writeIORef. The prefix "atomic" relates to a fact -- that it imposes a reordering barrier, similar to -- atomicModifyIORef. Such a write will not be reordered with -- other reads or writes even on CPUs with weak memory model. atomicWriteIORef :: IORef a -> a -> IO () -- | Reexports Data.IORef.Compat from a globally unique namespace. module Data.IORef.Compat.Repl module Data.Monoid.Compat -- | Boolean monoid under disjunction (||). -- --
--   >>> getAny (Any True <> mempty <> Any False)
--   True
--   
-- --
--   >>> getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
--   True
--   
newtype () => Any Any :: Bool -> Any [getAny] :: Any -> Bool -- | Monoid under addition. -- --
--   >>> getSum (Sum 1 <> Sum 2 <> mempty)
--   3
--   
newtype () => Sum a Sum :: a -> Sum a [getSum] :: Sum a -> a -- | Monoid under multiplication. -- --
--   >>> getProduct (Product 3 <> Product 4 <> mempty)
--   12
--   
newtype () => Product a Product :: a -> Product a [getProduct] :: Product a -> a -- | Maybe monoid returning the rightmost non-Nothing value. -- -- Last a is isomorphic to Dual (First -- a), and thus to Dual (Alt Maybe a) -- --
--   >>> getLast (Last (Just "hello") <> Last Nothing <> Last (Just "world"))
--   Just "world"
--   
-- -- Beware that Data.Monoid.Last is different from -- Data.Semigroup.Last. The former returns the last -- non-Nothing, so x <> Data.Monoid.Last Nothing = -- x. The latter simply returns the last value, thus x <> -- Data.Semigroup.Last Nothing = Data.Semigroup.Last Nothing. newtype () => Last a Last :: Maybe a -> Last a [getLast] :: Last a -> Maybe a -- | Maybe monoid returning the leftmost non-Nothing value. -- -- First a is isomorphic to Alt Maybe -- a, but precedes it historically. -- --
--   >>> getFirst (First (Just "hello") <> First Nothing <> First (Just "world"))
--   Just "hello"
--   
-- -- Beware that Data.Monoid.First is different from -- Data.Semigroup.First. The former returns the first -- non-Nothing, so Data.Monoid.First Nothing <> x = -- x. The latter simply returns the first value, thus -- Data.Semigroup.First Nothing <> x = Data.Semigroup.First -- Nothing. newtype () => First a First :: Maybe a -> First a [getFirst] :: First a -> Maybe a -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following: -- -- -- -- You can alternatively define mconcat instead of mempty, -- in which case the laws are: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. -- -- NOTE: Semigroup is a superclass of Monoid since -- base-4.11.0.0. class Semigroup a => Monoid a -- | Identity of mappend -- --
--   >>> "Hello world" <> mempty
--   "Hello world"
--   
mempty :: Monoid a => a -- | An associative operation -- -- NOTE: This method is redundant and has the default -- implementation mappend = (<>) since -- base-4.11.0.0. Should it be implemented manually, since -- mappend is a synonym for (<>), it is expected that -- the two functions are defined the same way. In a future GHC release -- mappend will be removed from Monoid. mappend :: Monoid a => a -> a -> a -- | Fold a list using the monoid. -- -- For most types, the default definition for mconcat will be -- used, but the function is included in the class definition so that an -- optimized version can be provided for specific types. -- --
--   >>> mconcat ["Hello", " ", "Haskell", "!"]
--   "Hello Haskell!"
--   
mconcat :: Monoid a => [a] -> a -- | Monoid under <|>. -- --
--   >>> getAlt (Alt (Just 12) <> Alt (Just 24))
--   Just 12
--   
-- --
--   >>> getAlt $ Alt Nothing <> Alt (Just 24)
--   Just 24
--   
newtype () => Alt (f :: k -> Type) (a :: k) Alt :: f a -> Alt (f :: k -> Type) (a :: k) [getAlt] :: Alt (f :: k -> Type) (a :: k) -> f a -- | Boolean monoid under conjunction (&&). -- --
--   >>> getAll (All True <> mempty <> All False)
--   False
--   
-- --
--   >>> getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
--   False
--   
newtype () => All All :: Bool -> All [getAll] :: All -> Bool -- | The monoid of endomorphisms under composition. -- --
--   >>> let computation = Endo ("Hello, " ++) <> Endo (++ "!")
--   
--   >>> appEndo computation "Haskell"
--   "Hello, Haskell!"
--   
newtype () => Endo a Endo :: (a -> a) -> Endo a [appEndo] :: Endo a -> a -> a -- | The dual of a Monoid, obtained by swapping the arguments of -- mappend. -- --
--   >>> getDual (mappend (Dual "Hello") (Dual "World"))
--   "WorldHello"
--   
newtype () => Dual a Dual :: a -> Dual a [getDual] :: Dual a -> a -- | This data type witnesses the lifting of a Monoid into an -- Applicative pointwise. newtype () => Ap (f :: k -> Type) (a :: k) Ap :: f a -> Ap (f :: k -> Type) (a :: k) [getAp] :: Ap (f :: k -> Type) (a :: k) -> f a -- | An associative operation. -- --
--   >>> [1,2,3] <> [4,5,6]
--   [1,2,3,4,5,6]
--   
(<>) :: Semigroup a => a -> a -> a infixr 6 <> -- | Reexports Data.Monoid.Compat from a globally unique namespace. module Data.Monoid.Compat.Repl module Data.Proxy.Compat -- | asProxyTypeOf is a type-restricted version of const. It -- is usually used as an infix operator, and its typing forces its first -- argument (which is usually overloaded) to have the same type as the -- tag of the second. -- --
--   >>> import Data.Word
--   
--   >>> :type asProxyTypeOf 123 (Proxy :: Proxy Word8)
--   asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8
--   
-- -- Note the lower-case proxy in the definition. This allows any -- type constructor with just one argument to be passed to the function, -- for example we could also write -- --
--   >>> import Data.Word
--   
--   >>> :type asProxyTypeOf 123 (Just (undefined :: Word8))
--   asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8
--   
asProxyTypeOf :: a -> proxy a -> a -- | Reexports Data.Proxy.Compat from a globally unique namespace. module Data.Proxy.Compat.Repl module Data.Ratio.Compat -- | Reexports Data.Ratio.Compat from a globally unique namespace. module Data.Ratio.Compat.Repl module Data.STRef.Compat -- | Strict version of modifySTRef modifySTRef' :: STRef s a -> (a -> a) -> ST s () -- | Reexports Data.STRef.Compat from a globally unique namespace. module Data.STRef.Compat.Repl -- | This backports the modern Data.Semigroup interface back to -- base-4.9/GHC 8.0. module Data.Semigroup.Compat -- | The class of semigroups (types with an associative binary operation). -- -- Instances should satisfy the following: -- -- -- -- You can alternatively define sconcat instead of -- (<>), in which case the laws are: -- -- class () => Semigroup a -- | An associative operation. -- --
--   >>> [1,2,3] <> [4,5,6]
--   [1,2,3,4,5,6]
--   
(<>) :: Semigroup a => a -> a -> a -- | Reduce a non-empty list with <> -- -- The default definition should be sufficient, but this can be -- overridden for efficiency. -- --
--   >>> import Data.List.NonEmpty (NonEmpty (..))
--   
--   >>> sconcat $ "Hello" :| [" ", "Haskell", "!"]
--   "Hello Haskell!"
--   
sconcat :: Semigroup a => NonEmpty a -> a -- | Repeat a value n times. -- -- Given that this works on a Semigroup it is allowed to fail if -- you request 0 or fewer repetitions, and the default definition will do -- so. -- -- By making this a member of the class, idempotent semigroups and -- monoids can upgrade this to execute in <math> by picking -- stimes = stimesIdempotent or stimes = -- stimesIdempotentMonoid respectively. -- --
--   >>> stimes 4 [1]
--   [1,1,1,1]
--   
stimes :: (Semigroup a, Integral b) => b -> a -> a infixr 6 <> -- | This is a valid definition of stimes for a Monoid. -- -- Unlike the default definition of stimes, it is defined for 0 -- and so it should be preferred where possible. stimesMonoid :: (Integral b, Monoid a) => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Semigroup. -- -- When x <> x = x, this definition should be preferred, -- because it works in <math> rather than <math>. stimesIdempotent :: Integral b => b -> a -> a -- | This is a valid definition of stimes for an idempotent -- Monoid. -- -- When mappend x x = x, this definition should be preferred, -- because it works in <math> rather than <math> stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a -- | Repeat a value n times. -- --
--   mtimesDefault n a = a <> a <> ... <> a  -- using <> (n-1) times
--   
-- -- In many cases, `stimes 0 a` for a Monoid will produce -- mempty. However, there are situations when it cannot do so. In -- particular, the following situation is fairly common: -- --
--   data T a = ...
--   
--   class Constraint1 a
--   class Constraint1 a => Constraint2 a
--   
-- -- instance Constraint1 a => Semigroup (T a) instance -- Constraint2 a => Monoid (T a) @ -- -- Since Constraint1 is insufficient to implement mempty, -- stimes for T a cannot do so. -- -- When working with such a type, or when working polymorphically with -- Semigroup instances, mtimesDefault should be used when -- the multiplier might be zero. It is implemented using stimes -- when the multiplier is nonzero and mempty when it is zero. mtimesDefault :: (Integral b, Monoid a) => b -> a -> a newtype () => Min a Min :: a -> Min a [getMin] :: Min a -> a newtype () => Max a Max :: a -> Max a [getMax] :: Max a -> a -- | Beware that Data.Semigroup.First is different from -- Data.Monoid.First. The former simply returns the first -- value, so Data.Semigroup.First Nothing <> x = -- Data.Semigroup.First Nothing. The latter returns the first -- non-Nothing, thus Data.Monoid.First Nothing <> x = -- x. newtype () => First a First :: a -> First a [getFirst] :: First a -> a -- | Beware that Data.Semigroup.Last is different from -- Data.Monoid.Last. The former simply returns the last -- value, so x <> Data.Semigroup.Last Nothing = -- Data.Semigroup.Last Nothing. The latter returns the last -- non-Nothing, thus x <> Data.Monoid.Last Nothing = -- x. newtype () => Last a Last :: a -> Last a [getLast] :: Last a -> a -- | Provide a Semigroup for an arbitrary Monoid. -- -- NOTE: This is not needed anymore since Semigroup became -- a superclass of Monoid in base-4.11 and this newtype be -- deprecated at some point in the future. newtype () => WrappedMonoid m WrapMonoid :: m -> WrappedMonoid m [unwrapMonoid] :: WrappedMonoid m -> m -- | The dual of a Monoid, obtained by swapping the arguments of -- mappend. -- --
--   >>> getDual (mappend (Dual "Hello") (Dual "World"))
--   "WorldHello"
--   
newtype () => Dual a Dual :: a -> Dual a [getDual] :: Dual a -> a -- | The monoid of endomorphisms under composition. -- --
--   >>> let computation = Endo ("Hello, " ++) <> Endo (++ "!")
--   
--   >>> appEndo computation "Haskell"
--   "Hello, Haskell!"
--   
newtype () => Endo a Endo :: (a -> a) -> Endo a [appEndo] :: Endo a -> a -> a -- | Boolean monoid under conjunction (&&). -- --
--   >>> getAll (All True <> mempty <> All False)
--   False
--   
-- --
--   >>> getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
--   False
--   
newtype () => All All :: Bool -> All [getAll] :: All -> Bool -- | Boolean monoid under disjunction (||). -- --
--   >>> getAny (Any True <> mempty <> Any False)
--   True
--   
-- --
--   >>> getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
--   True
--   
newtype () => Any Any :: Bool -> Any [getAny] :: Any -> Bool -- | Monoid under addition. -- --
--   >>> getSum (Sum 1 <> Sum 2 <> mempty)
--   3
--   
newtype () => Sum a Sum :: a -> Sum a [getSum] :: Sum a -> a -- | Monoid under multiplication. -- --
--   >>> getProduct (Product 3 <> Product 4 <> mempty)
--   12
--   
newtype () => Product a Product :: a -> Product a [getProduct] :: Product a -> a -- | This lets you use a difference list of a Semigroup as a -- Monoid. -- --

Example:

-- --
--   >>> let hello = diff "Hello, "
--   
--   >>> appEndo hello "World!"
--   "Hello, World!"
--   
--   >>> appEndo (hello <> mempty) "World!"
--   "Hello, World!"
--   
--   >>> appEndo (mempty <> hello) "World!"
--   "Hello, World!"
--   
--   >>> let world = diff "World"
--   
--   >>> let excl = diff "!"
--   
--   >>> appEndo (hello <> (world <> excl)) mempty
--   "Hello, World!"
--   
--   >>> appEndo ((hello <> world) <> excl) mempty
--   "Hello, World!"
--   
diff :: Semigroup m => m -> Endo m -- | A generalization of cycle to an arbitrary Semigroup. May -- fail to terminate for some values in some semigroups. cycle1 :: Semigroup m => m -> m -- | Arg isn't itself a Semigroup in its own right, but it -- can be placed inside Min and Max to compute an arg min -- or arg max. -- --
--   >>> minimum [ Arg (x * x) x | x <- [-10 .. 10] ]
--   Arg 0 0
--   
data () => Arg a b Arg :: a -> b -> Arg a b -- |
--   >>> Min (Arg 0 ()) <> Min (Arg 1 ())
--   Min {getMin = Arg 0 ()}
--   
type ArgMin a b = Min Arg a b -- |
--   >>> Max (Arg 0 ()) <> Max (Arg 1 ())
--   Max {getMax = Arg 1 ()}
--   
type ArgMax a b = Max Arg a b -- | Reexports Data.Semigroup.Compat from a globally unique -- namespace. module Data.Semigroup.Compat.Repl module Data.String.Compat -- | A String is a list of characters. String constants in Haskell -- are values of type String. -- -- See Data.List for operations on lists. type String = [Char] -- | Splits the argument into a list of lines stripped of their -- terminating \n characters. The \n terminator is -- optional in a final non-empty line of the argument string. -- -- For example: -- --
--   >>> lines ""           -- empty input contains no lines
--   []
--   
--   >>> lines "\n"         -- single empty line
--   [""]
--   
--   >>> lines "one"        -- single unterminated line
--   ["one"]
--   
--   >>> lines "one\n"      -- single non-empty line
--   ["one"]
--   
--   >>> lines "one\n\n"    -- second line is empty
--   ["one",""]
--   
--   >>> lines "one\ntwo"   -- second line is unterminated
--   ["one","two"]
--   
--   >>> lines "one\ntwo\n" -- two non-empty lines
--   ["one","two"]
--   
-- -- When the argument string is empty, or ends in a \n character, -- it can be recovered by passing the result of lines to the -- unlines function. Otherwise, unlines appends the missing -- terminating \n. This makes unlines . lines -- idempotent: -- --
--   (unlines . lines) . (unlines . lines) = (unlines . lines)
--   
lines :: String -> [String] -- | words breaks a string up into a list of words, which were -- delimited by white space (as defined by isSpace). This function -- trims any white spaces at the beginning and at the end. -- --
--   >>> words "Lorem ipsum\ndolor"
--   ["Lorem","ipsum","dolor"]
--   
--   >>> words " foo bar "
--   ["foo","bar"]
--   
words :: String -> [String] -- | Appends a \n character to each input string, then -- concatenates the results. Equivalent to foldMap (s -> -- s ++ "\n"). -- --
--   >>> unlines ["Hello", "World", "!"]
--   "Hello\nWorld\n!\n"
--   
-- -- Note that unlines . lines /= -- id when the input is not \n-terminated: -- --
--   >>> unlines . lines $ "foo\nbar"
--   "foo\nbar\n"
--   
unlines :: [String] -> String -- | unwords joins words with separating spaces (U+0020 SPACE). -- --
--   >>> unwords ["Lorem", "ipsum", "dolor"]
--   "Lorem ipsum dolor"
--   
-- -- unwords is neither left nor right inverse of words: -- --
--   >>> words (unwords [" "])
--   []
--   
--   >>> unwords (words "foo\nbar")
--   "foo bar"
--   
unwords :: [String] -> String -- | Reexports Data.String.Compat from a globally unique namespace. module Data.String.Compat.Repl module Data.Traversable.Compat -- | The mapAccumM function behaves like a combination of -- mapM and mapAccumL that traverses the structure while -- evaluating the actions and passing an accumulating parameter from left -- to right. It returns a final value of this accumulator together with -- the new structure. The accummulator is often used for caching the -- intermediate results of a computation. -- --

Examples

-- -- Basic usage: -- --
--   >>> let expensiveDouble a = putStrLn ("Doubling " <> show a) >> pure (2 * a)
--   
--   >>> :{
--   mapAccumM (\cache a -> case lookup a cache of
--       Nothing -> expensiveDouble a >>= \double -> pure ((a, double):cache, double)
--       Just double -> pure (cache, double)
--       ) [] [1, 2, 3, 1, 2, 3]
--   :}
--   Doubling 1
--   Doubling 2
--   Doubling 3
--   ([(3,6),(2,4),(1,2)],[2,4,6,2,4,6])
--   
mapAccumM :: (Monad m, Traversable t) => (s -> a -> m (s, b)) -> s -> t a -> m (s, t b) -- | forAccumM is mapAccumM with the arguments rearranged. forAccumM :: (Monad m, Traversable t) => s -> t a -> (s -> a -> m (s, b)) -> m (s, t b) -- | Reexports Data.Traversable.Compat from a globally unique -- namespace. module Data.Traversable.Compat.Repl -- | Note that we only re-export MkSolo when building with -- ghc-prim-0.10.0 (bundled with GHC 9.6) or later. If you want -- to backport MkSolo to older versions of GHC, import -- Data.Tuple.Compat from base-compat-batteries -- instead. module Data.Tuple.Compat -- | Extract the first component of a pair. fst :: (a, b) -> a -- | Extract the second component of a pair. snd :: (a, b) -> b -- | curry converts an uncurried function to a curried function. -- --

Examples

-- --
--   >>> curry fst 1 2
--   1
--   
curry :: ((a, b) -> c) -> a -> b -> c -- | uncurry converts a curried function to a function on pairs. -- --

Examples

-- --
--   >>> uncurry (+) (1,2)
--   3
--   
-- --
--   >>> uncurry ($) (show, 1)
--   "1"
--   
-- --
--   >>> map (uncurry max) [(1,2), (3,4), (6,8)]
--   [2,4,8]
--   
uncurry :: (a -> b -> c) -> (a, b) -> c -- | Swap the components of a pair. swap :: (a, b) -> (b, a) -- | Solo is the canonical lifted 1-tuple, just like (,) -- is the canonical lifted 2-tuple (pair) and (,,) is the -- canonical lifted 3-tuple (triple). -- -- The most important feature of Solo is that it is possible to -- force its "outside" (usually by pattern matching) without forcing its -- "inside", because it is defined as a datatype rather than a newtype. -- One situation where this can be useful is when writing a function to -- extract a value from a data structure. Suppose you write an -- implementation of arrays and offer only this function to index into -- them: -- --
--   index :: Array a -> Int -> a
--   
-- -- Now imagine that someone wants to extract a value from an array and -- store it in a lazy-valued finite map/dictionary: -- --
--   insert "hello" (arr index 12) m
--   
-- -- This can actually lead to a space leak. The value is not actually -- extracted from the array until that value (now buried in a map) is -- forced. That means the entire array may be kept live by just that -- value! Often, the solution is to use a strict map, or to force the -- value before storing it, but for some purposes that's undesirable. -- -- One common solution is to include an indexing function that can -- produce its result in an arbitrary Applicative context: -- --
--   indexA :: Applicative f => Array a -> Int -> f a
--   
-- -- When using indexA in a pure context, Solo -- serves as a handy Applicative functor to hold the result. You -- could write a non-leaky version of the above example thus: -- --
--   case arr indexA 12 of
--     Solo a -> insert "hello" a m
--   
-- -- While such simple extraction functions are the most common uses for -- unary tuples, they can also be useful for fine-grained control of -- strict-spined data structure traversals, and for unifying the -- implementations of lazy and strict mapping functions. data () => Solo a MkSolo :: a -> Solo a pattern Solo :: a -> Solo a getSolo :: Solo a -> a -- | Reexports Data.Tuple.Compat from a globally unique namespace. module Data.Tuple.Compat.Repl module Data.Type.Coercion.Compat -- | Generalized form of type-safe cast using representational equality gcoerceWith :: forall {k} (a :: k) (b :: k) r. Coercion a b -> (Coercible a b => r) -> r -- | Reexports Data.Type.Coercion.Compat from a globally unique -- namespace. module Data.Type.Coercion.Compat.Repl module Data.Type.Equality.Compat -- | Reexports Data.Type.Equality.Compat from a globally unique -- namespace. module Data.Type.Equality.Compat.Repl module Data.Version.Compat -- | Construct tag-less Version makeVersion :: [Int] -> Version -- | Reexports Data.Version.Compat from a globally unique namespace. module Data.Version.Compat.Repl module Data.Void.Compat -- | Reexports Data.Void.Compat from a globally unique namespace. module Data.Void.Compat.Repl module Data.Word.Compat -- | Reverse order of bytes in Word16. byteSwap16 :: Word16 -> Word16 -- | Reverse order of bytes in Word32. byteSwap32 :: Word32 -> Word32 -- | Reverse order of bytes in Word64. byteSwap64 :: Word64 -> Word64 -- | Reexports Data.Word.Compat from a globally unique namespace. module Data.Word.Compat.Repl module Debug.Trace.Compat -- | Like trace but returns the message instead of a third value. -- --
--   >>> traceId "hello"
--   hello
--   "hello"
--   
traceId :: String -> String -- | Like traceShow but returns the shown value instead of a third -- value. -- --
--   >>> traceShowId (1+2+3, "hello" ++ "world")
--   (6,"helloworld")
--   (6,"helloworld")
--   
traceShowId :: Show a => a -> a -- | Like trace but returning unit in an arbitrary -- Applicative context. Allows for convenient use in do-notation. -- -- Note that the application of traceM is not an action in the -- Applicative context, as traceIO is in the IO -- type. While the fresh bindings in the following example will force the -- traceM expressions to be reduced every time the -- do-block is executed, traceM "not crashed" would -- only be reduced once, and the message would only be printed once. If -- your monad is in MonadIO, liftIO . -- traceIO may be a better option. -- --
--   >>> :{
--   do
--       x <- Just 3
--       traceM ("x: " ++ show x)
--       y <- pure 12
--       traceM ("y: " ++ show y)
--       pure (x*2 + y)
--   :}
--   x: 3
--   y: 12
--   Just 18
--   
traceM :: Applicative f => String -> f () -- | Like traceM, but uses show on the argument to convert it -- to a String. -- --
--   >>> :{
--   do
--       x <- Just 3
--       traceShowM x
--       y <- pure 12
--       traceShowM y
--       pure (x*2 + y)
--   :}
--   3
--   12
--   Just 18
--   
traceShowM :: (Show a, Applicative f) => a -> f () -- | Like trace, but outputs the result of calling a function on the -- argument. -- --
--   >>> traceWith fst ("hello","world")
--   hello
--   ("hello","world")
--   
traceWith :: (a -> String) -> a -> a -- | Like traceWith, but uses show on the result of the -- function to convert it to a String. -- --
--   >>> traceShowWith length [1,2,3]
--   3
--   [1,2,3]
--   
traceShowWith :: Show b => (a -> b) -> a -> a -- | Like traceEvent, but emits the result of calling a function on -- its argument. traceEventWith :: (a -> String) -> a -> a -- | Reexports Debug.Trace.Compat from a globally unique namespace. module Debug.Trace.Compat.Repl module Foreign.ForeignPtr.Compat -- | Advances the given address by the given offset in bytes. -- -- The new ForeignPtr shares the finalizer of the original, -- equivalent from a finalization standpoint to just creating another -- reference to the original. That is, the finalizer will not be called -- before the new ForeignPtr is unreachable, nor will it be called -- an additional time due to this call, and the finalizer will be called -- with the same address that it would have had this call not happened, -- *not* the new address. plusForeignPtr :: ForeignPtr a -> Int -> ForeignPtr b -- | Reexports Foreign.ForeignPtr.Compat from a globally unique -- namespace. module Foreign.ForeignPtr.Compat.Repl module Foreign.ForeignPtr.Safe.Compat -- | The type ForeignPtr represents references to objects that are -- maintained in a foreign language, i.e., that are not part of the data -- structures usually managed by the Haskell storage manager. The -- essential difference between ForeignPtrs and vanilla memory -- references of type Ptr a is that the former may be associated -- with finalizers. A finalizer is a routine that is invoked when -- the Haskell storage manager detects that - within the Haskell heap and -- stack - there are no more references left that are pointing to the -- ForeignPtr. Typically, the finalizer will, then, invoke -- routines in the foreign language that free the resources bound by the -- foreign object. -- -- The ForeignPtr is parameterised in the same way as Ptr. -- The type argument of ForeignPtr should normally be an instance -- of class Storable. data () => ForeignPtr a -- | A finalizer is represented as a pointer to a foreign function that, at -- finalisation time, gets as an argument a plain pointer variant of the -- foreign pointer that the finalizer is associated with. -- -- Note that the foreign function must use the ccall -- calling convention. type FinalizerPtr a = FunPtr Ptr a -> IO () type FinalizerEnvPtr env a = FunPtr Ptr env -> Ptr a -> IO () -- | Turns a plain memory reference into a foreign pointer, and associates -- a finalizer with the reference. The finalizer will be executed after -- the last reference to the foreign object is dropped. There is no -- guarantee of promptness, however the finalizer will be executed before -- the program exits. newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a) -- | Turns a plain memory reference into a foreign pointer that may be -- associated with finalizers by using addForeignPtrFinalizer. newForeignPtr_ :: Ptr a -> IO (ForeignPtr a) -- | This function adds a finalizer to the given foreign object. The -- finalizer will run before all other finalizers for the same -- object which have already been registered. addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO () -- | This variant of newForeignPtr adds a finalizer that expects an -- environment in addition to the finalized pointer. The environment that -- will be passed to the finalizer is fixed by the second argument to -- newForeignPtrEnv. newForeignPtrEnv :: FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a) -- | Like addForeignPtrFinalizer but the finalizer is passed an -- additional environment parameter. addForeignPtrFinalizerEnv :: FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO () -- | This is a way to look at the pointer living inside a foreign object. -- This function takes a function which is applied to that pointer. The -- resulting IO action is then executed. The foreign object is -- kept alive at least during the whole action, even if it is not used -- directly inside. Note that it is not safe to return the pointer from -- the action and use it after the action completes. All uses of the -- pointer should be inside the withForeignPtr bracket. The reason -- for this unsafeness is the same as for unsafeForeignPtrToPtr -- below: the finalizer may run earlier than expected, because the -- compiler can only track usage of the ForeignPtr object, not a -- Ptr object made from it. -- -- This function is normally used for marshalling data to or from the -- object pointed to by the ForeignPtr, using the operations from -- the Storable class. withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b -- | Causes the finalizers associated with a foreign pointer to be run -- immediately. The foreign pointer must not be used again after this -- function is called. If the foreign pointer does not support -- finalizers, this is a no-op. finalizeForeignPtr :: ForeignPtr a -> IO () -- | This function ensures that the foreign object in question is alive at -- the given place in the sequence of IO actions. However, this comes -- with a significant caveat: the contract above does not hold if GHC can -- demonstrate that the code preceding touchForeignPtr diverges -- (e.g. by looping infinitely or throwing an exception). For this -- reason, you are strongly advised to use instead withForeignPtr -- where possible. -- -- Also, note that this function should not be used to express -- dependencies between finalizers on ForeignPtrs. For example, if -- the finalizer for a ForeignPtr F1 calls -- touchForeignPtr on a second ForeignPtr F2, then -- the only guarantee is that the finalizer for F2 is never -- started before the finalizer for F1. They might be started -- together if for example both F1 and F2 are otherwise -- unreachable, and in that case the scheduler might end up running the -- finalizer for F2 first. -- -- In general, it is not recommended to use finalizers on separate -- objects with ordering constraints between them. To express the -- ordering robustly requires explicit synchronisation using -- MVars between the finalizers, but even then the runtime -- sometimes runs multiple finalizers sequentially in a single thread -- (for performance reasons), so synchronisation between finalizers could -- result in artificial deadlock. Another alternative is to use explicit -- reference counting. touchForeignPtr :: ForeignPtr a -> IO () -- | This function casts a ForeignPtr parameterised by one type into -- another type. castForeignPtr :: ForeignPtr a -> ForeignPtr b -- | Allocate some memory and return a ForeignPtr to it. The memory -- will be released automatically when the ForeignPtr is -- discarded. -- -- mallocForeignPtr is equivalent to -- --
--   do { p <- malloc; newForeignPtr finalizerFree p }
--   
-- -- although it may be implemented differently internally: you may not -- assume that the memory returned by mallocForeignPtr has been -- allocated with malloc. -- -- GHC notes: mallocForeignPtr has a heavily optimised -- implementation in GHC. It uses pinned memory in the garbage collected -- heap, so the ForeignPtr does not require a finalizer to free -- the memory. Use of mallocForeignPtr and associated functions is -- strongly recommended in preference to newForeignPtr with a -- finalizer. mallocForeignPtr :: Storable a => IO (ForeignPtr a) -- | This function is similar to mallocForeignPtr, except that the -- size of the memory required is given explicitly as a number of bytes. mallocForeignPtrBytes :: Int -> IO (ForeignPtr a) -- | This function is similar to mallocArray, but yields a memory -- area that has a finalizer attached that releases the memory area. As -- with mallocForeignPtr, it is not guaranteed that the block of -- memory was allocated by malloc. mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a) -- | This function is similar to mallocArray0, but yields a memory -- area that has a finalizer attached that releases the memory area. As -- with mallocForeignPtr, it is not guaranteed that the block of -- memory was allocated by malloc. mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a) -- | Reexports Foreign.ForeignPtr.Safe.Compat from a globally unique -- namespace. module Foreign.ForeignPtr.Safe.Compat.Repl module Foreign.ForeignPtr.Unsafe.Compat -- | This function extracts the pointer component of a foreign pointer. -- This is a potentially dangerous operations, as if the argument to -- unsafeForeignPtrToPtr is the last usage occurrence of the given -- foreign pointer, then its finalizer(s) will be run, which potentially -- invalidates the plain pointer just obtained. Hence, -- touchForeignPtr must be used wherever it has to be guaranteed -- that the pointer lives on - i.e., has another usage occurrence. -- -- To avoid subtle coding errors, hand written marshalling code should -- preferably use withForeignPtr rather than combinations of -- unsafeForeignPtrToPtr and touchForeignPtr. However, the -- latter routines are occasionally preferred in tool generated -- marshalling code. unsafeForeignPtrToPtr :: ForeignPtr a -> Ptr a -- | Reexports Foreign.ForeignPtr.Unsafe.Compat from a globally -- unique namespace. module Foreign.ForeignPtr.Unsafe.Compat.Repl module Foreign.Marshal.Alloc.Compat -- | Like malloc but memory is filled with bytes of value zero. calloc :: Storable a => IO (Ptr a) -- | Like mallocBytes, but memory is filled with bytes of value -- zero. callocBytes :: Int -> IO (Ptr a) -- | Reexports Foreign.Marshal.Alloc.Compat from a globally unique -- namespace. module Foreign.Marshal.Alloc.Compat.Repl module Foreign.Marshal.Array.Compat -- | Like mallocArray, but allocated memory is filled with bytes of -- value zero. callocArray :: Storable a => Int -> IO (Ptr a) -- | Like callocArray0, but allocated memory is filled with bytes of -- value zero. callocArray0 :: Storable a => Int -> IO (Ptr a) -- | Reexports Foreign.Marshal.Array.Compat from a globally unique -- namespace. module Foreign.Marshal.Array.Compat.Repl module Foreign.Marshal.Safe.Compat -- | Reexports Foreign.Marshal.Safe.Compat from a globally unique -- namespace. module Foreign.Marshal.Safe.Compat.Repl module Foreign.Marshal.Unsafe.Compat -- | Sometimes an external entity is a pure function, except that it passes -- arguments and/or results via pointers. The function -- unsafeLocalState permits the packaging of such entities as -- pure functions. -- -- The only IO operations allowed in the IO action passed to -- unsafeLocalState are (a) local allocation (alloca, -- allocaBytes and derived operations such as withArray -- and withCString), and (b) pointer operations -- (Foreign.Storable and Foreign.Ptr) on the pointers -- to local storage, and (c) foreign functions whose only observable -- effect is to read and/or write the locally allocated memory. Passing -- an IO operation that does not obey these rules results in undefined -- behaviour. -- -- It is expected that this operation will be replaced in a future -- revision of Haskell. unsafeLocalState :: IO a -> a -- | Reexports Foreign.Marshal.Unsafe.Compat from a globally unique -- namespace. module Foreign.Marshal.Unsafe.Compat.Repl module Foreign.Marshal.Utils.Compat -- | Fill a given number of bytes in memory area with a byte value. fillBytes :: Ptr a -> Word8 -> Int -> IO () module Foreign.Marshal.Compat -- | Reexports Foreign.Marshal.Compat from a globally unique -- namespace. module Foreign.Marshal.Compat.Repl module Foreign.Compat -- | Reexports Foreign.Compat from a globally unique namespace. module Foreign.Compat.Repl -- | Reexports Foreign.Marshal.Utils.Compat from a globally unique -- namespace. module Foreign.Marshal.Utils.Compat.Repl module Numeric.Compat -- | Show non-negative Integral numbers in base 2. showBin :: Integral a => a -> ShowS -- | Show a signed RealFloat value using standard decimal notation -- (e.g. 245000, 0.0015). -- -- This behaves as showFFloat, except that a decimal point is -- always guaranteed, even if not needed. showFFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS -- | Show a signed RealFloat value using standard decimal notation -- for arguments whose absolute value lies between 0.1 and -- 9,999,999, and scientific notation otherwise. -- -- This behaves as showFFloat, except that a decimal point is -- always guaranteed, even if not needed. showGFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS -- | Show a floating-point value in the hexadecimal format, similar to the -- %a specifier in C's printf. -- --
--   >>> showHFloat (212.21 :: Double) ""
--   "0x1.a86b851eb851fp7"
--   
--   >>> showHFloat (-12.76 :: Float) ""
--   "-0x1.9851ecp3"
--   
--   >>> showHFloat (-0 :: Double) ""
--   "-0x0p+0"
--   
showHFloat :: RealFloat a => a -> ShowS -- | Read an unsigned number in binary notation. -- --
--   >>> readBin "10011"
--   [(19,"")]
--   
readBin :: (Eq a, Num a) => ReadS a -- | Reexports Numeric.Compat from a globally unique namespace. module Numeric.Compat.Repl module Numeric.Natural.Compat -- | Natural subtraction. Returns Nothings for non-positive -- results. minusNaturalMaybe :: Natural -> Natural -> Maybe Natural -- | Reexports Numeric.Natural.Compat from a globally unique -- namespace. module Numeric.Natural.Compat.Repl module Prelude.Compat -- | Case analysis for the Either type. If the value is -- Left a, apply the first function to a; if it -- is Right b, apply the second function to b. -- --

Examples

-- -- We create two values of type Either String -- Int, one using the Left constructor and another -- using the Right constructor. Then we apply "either" the -- length function (if we have a String) or the "times-two" -- function (if we have an Int): -- --
--   >>> let s = Left "foo" :: Either String Int
--   
--   >>> let n = Right 3 :: Either String Int
--   
--   >>> either length (*2) s
--   3
--   
--   >>> either length (*2) n
--   6
--   
either :: (a -> c) -> (b -> c) -> Either a b -> c -- | Determines whether all elements of the structure satisfy the -- predicate. -- --

Examples

-- -- Basic usage: -- --
--   >>> all (> 3) []
--   True
--   
-- --
--   >>> all (> 3) [1,2]
--   False
--   
-- --
--   >>> all (> 3) [1,2,3,4,5]
--   False
--   
-- --
--   >>> all (> 3) [1..]
--   False
--   
-- --
--   >>> all (> 3) [4..]
--   * Hangs forever *
--   
all :: Foldable t => (a -> Bool) -> t a -> Bool -- | and returns the conjunction of a container of Bools. For the -- result to be True, the container must be finite; False, -- however, results from a False value finitely far from the left -- end. -- --

Examples

-- -- Basic usage: -- --
--   >>> and []
--   True
--   
-- --
--   >>> and [True]
--   True
--   
-- --
--   >>> and [False]
--   False
--   
-- --
--   >>> and [True, True, False]
--   False
--   
-- --
--   >>> and (False : repeat True) -- Infinite list [False,True,True,True,...
--   False
--   
-- --
--   >>> and (repeat True)
--   * Hangs forever *
--   
and :: Foldable t => t Bool -> Bool -- | Determines whether any element of the structure satisfies the -- predicate. -- --

Examples

-- -- Basic usage: -- --
--   >>> any (> 3) []
--   False
--   
-- --
--   >>> any (> 3) [1,2]
--   False
--   
-- --
--   >>> any (> 3) [1,2,3,4,5]
--   True
--   
-- --
--   >>> any (> 3) [1..]
--   True
--   
-- --
--   >>> any (> 3) [0, -1..]
--   * Hangs forever *
--   
any :: Foldable t => (a -> Bool) -> t a -> Bool -- | The concatenation of all the elements of a container of lists. -- --

Examples

-- -- Basic usage: -- --
--   >>> concat (Just [1, 2, 3])
--   [1,2,3]
--   
-- --
--   >>> concat (Left 42)
--   []
--   
-- --
--   >>> concat [[1, 2, 3], [4, 5], [6], []]
--   [1,2,3,4,5,6]
--   
concat :: Foldable t => t [a] -> [a] -- | Map a function over all the elements of a container and concatenate -- the resulting lists. -- --

Examples

-- -- Basic usage: -- --
--   >>> concatMap (take 3) [[1..], [10..], [100..], [1000..]]
--   [1,2,3,10,11,12,100,101,102,1000,1001,1002]
--   
-- --
--   >>> concatMap (take 3) (Just [1..])
--   [1,2,3]
--   
concatMap :: Foldable t => (a -> [b]) -> t a -> [b] -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. For a version that -- doesn't ignore the results see mapM. -- -- mapM_ is just like traverse_, but specialised to monadic -- actions. mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m () -- | notElem is the negation of elem. -- --

Examples

-- -- Basic usage: -- --
--   >>> 3 `notElem` []
--   True
--   
-- --
--   >>> 3 `notElem` [1,2]
--   True
--   
-- --
--   >>> 3 `notElem` [1,2,3,4,5]
--   False
--   
-- -- For infinite structures, notElem terminates if the value exists -- at a finite distance from the left side of the structure: -- --
--   >>> 3 `notElem` [1..]
--   False
--   
-- --
--   >>> 3 `notElem` ([4..] ++ [3])
--   * Hangs forever *
--   
notElem :: (Foldable t, Eq a) => a -> t a -> Bool infix 4 `notElem` -- | or returns the disjunction of a container of Bools. For the -- result to be False, the container must be finite; True, -- however, results from a True value finitely far from the left -- end. -- --

Examples

-- -- Basic usage: -- --
--   >>> or []
--   False
--   
-- --
--   >>> or [True]
--   True
--   
-- --
--   >>> or [False]
--   False
--   
-- --
--   >>> or [True, True, False]
--   True
--   
-- --
--   >>> or (True : repeat False) -- Infinite list [True,False,False,False,...
--   True
--   
-- --
--   >>> or (repeat False)
--   * Hangs forever *
--   
or :: Foldable t => t Bool -> Bool -- | Evaluate each monadic action in the structure from left to right, and -- ignore the results. For a version that doesn't ignore the results see -- sequence. -- -- sequence_ is just like sequenceA_, but specialised to -- monadic actions. sequence_ :: (Foldable t, Monad m) => t (m a) -> m () -- | An infix synonym for fmap. -- -- The name of this operator is an allusion to $. Note the -- similarities between their types: -- --
--    ($)  ::              (a -> b) ->   a ->   b
--   (<$>) :: Functor f => (a -> b) -> f a -> f b
--   
-- -- Whereas $ is function application, <$> is function -- application lifted over a Functor. -- --

Examples

-- -- Convert from a Maybe Int to a Maybe -- String using show: -- --
--   >>> show <$> Nothing
--   Nothing
--   
--   >>> show <$> Just 3
--   Just "3"
--   
-- -- Convert from an Either Int Int to an -- Either Int String using show: -- --
--   >>> show <$> Left 17
--   Left 17
--   
--   >>> show <$> Right 17
--   Right "17"
--   
-- -- Double each element of a list: -- --
--   >>> (*2) <$> [1,2,3]
--   [2,4,6]
--   
-- -- Apply even to the second element of a pair: -- --
--   >>> even <$> (2,2)
--   (2,True)
--   
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 <$> -- | The maybe function takes a default value, a function, and a -- Maybe value. If the Maybe value is Nothing, the -- function returns the default value. Otherwise, it applies the function -- to the value inside the Just and returns the result. -- --

Examples

-- -- Basic usage: -- --
--   >>> maybe False odd (Just 3)
--   True
--   
-- --
--   >>> maybe False odd Nothing
--   False
--   
-- -- Read an integer from a string using readMaybe. If we succeed, -- return twice the integer; that is, apply (*2) to it. If -- instead we fail to parse an integer, return 0 by default: -- --
--   >>> import Text.Read ( readMaybe )
--   
--   >>> maybe 0 (*2) (readMaybe "5")
--   10
--   
--   >>> maybe 0 (*2) (readMaybe "")
--   0
--   
-- -- Apply show to a Maybe Int. If we have Just n, -- we want to show the underlying Int n. But if we have -- Nothing, we return the empty string instead of (for example) -- "Nothing": -- --
--   >>> maybe "" show (Just 5)
--   "5"
--   
--   >>> maybe "" show Nothing
--   ""
--   
maybe :: b -> (a -> b) -> Maybe a -> b -- | Splits the argument into a list of lines stripped of their -- terminating \n characters. The \n terminator is -- optional in a final non-empty line of the argument string. -- -- For example: -- --
--   >>> lines ""           -- empty input contains no lines
--   []
--   
--   >>> lines "\n"         -- single empty line
--   [""]
--   
--   >>> lines "one"        -- single unterminated line
--   ["one"]
--   
--   >>> lines "one\n"      -- single non-empty line
--   ["one"]
--   
--   >>> lines "one\n\n"    -- second line is empty
--   ["one",""]
--   
--   >>> lines "one\ntwo"   -- second line is unterminated
--   ["one","two"]
--   
--   >>> lines "one\ntwo\n" -- two non-empty lines
--   ["one","two"]
--   
-- -- When the argument string is empty, or ends in a \n character, -- it can be recovered by passing the result of lines to the -- unlines function. Otherwise, unlines appends the missing -- terminating \n. This makes unlines . lines -- idempotent: -- --
--   (unlines . lines) . (unlines . lines) = (unlines . lines)
--   
lines :: String -> [String] -- | Appends a \n character to each input string, then -- concatenates the results. Equivalent to foldMap (s -> -- s ++ "\n"). -- --
--   >>> unlines ["Hello", "World", "!"]
--   "Hello\nWorld\n!\n"
--   
-- -- Note that unlines . lines /= -- id when the input is not \n-terminated: -- --
--   >>> unlines . lines $ "foo\nbar"
--   "foo\nbar\n"
--   
unlines :: [String] -> String -- | unwords joins words with separating spaces (U+0020 SPACE). -- --
--   >>> unwords ["Lorem", "ipsum", "dolor"]
--   "Lorem ipsum dolor"
--   
-- -- unwords is neither left nor right inverse of words: -- --
--   >>> words (unwords [" "])
--   []
--   
--   >>> unwords (words "foo\nbar")
--   "foo bar"
--   
unwords :: [String] -> String -- | words breaks a string up into a list of words, which were -- delimited by white space (as defined by isSpace). This function -- trims any white spaces at the beginning and at the end. -- --
--   >>> words "Lorem ipsum\ndolor"
--   ["Lorem","ipsum","dolor"]
--   
--   >>> words " foo bar "
--   ["foo","bar"]
--   
words :: String -> [String] -- | curry converts an uncurried function to a curried function. -- --

Examples

-- --
--   >>> curry fst 1 2
--   1
--   
curry :: ((a, b) -> c) -> a -> b -> c -- | Extract the first component of a pair. fst :: (a, b) -> a -- | Extract the second component of a pair. snd :: (a, b) -> b -- | uncurry converts a curried function to a function on pairs. -- --

Examples

-- --
--   >>> uncurry (+) (1,2)
--   3
--   
-- --
--   >>> uncurry ($) (show, 1)
--   "1"
--   
-- --
--   >>> map (uncurry max) [(1,2), (3,4), (6,8)]
--   [2,4,8]
--   
uncurry :: (a -> b -> c) -> (a, b) -> c -- | Strict (call-by-value) application operator. It takes a function and -- an argument, evaluates the argument to weak head normal form (WHNF), -- then calls the function with that value. ($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 $! -- | Append two lists, i.e., -- --
--   [x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
--   [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
--   
-- -- If the first list is not finite, the result is the first list. -- -- WARNING: This function takes linear time in the number of elements of -- the first list. (++) :: [a] -> [a] -> [a] infixr 5 ++ -- | Function composition. (.) :: (b -> c) -> (a -> b) -> a -> c infixr 9 . -- | Same as >>=, but with the arguments interchanged. (=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 =<< -- | asTypeOf is a type-restricted version of const. It is -- usually used as an infix operator, and its typing forces its first -- argument (which is usually overloaded) to have the same type as the -- second. asTypeOf :: a -> a -> a -- | const x y always evaluates to x, ignoring its second -- argument. -- --
--   >>> const 42 "hello"
--   42
--   
-- --
--   >>> map (const 42) [0..3]
--   [42,42,42,42]
--   
const :: a -> b -> a -- | flip f takes its (first) two arguments in the reverse -- order of f. -- --
--   >>> flip (++) "hello" "world"
--   "worldhello"
--   
flip :: (a -> b -> c) -> b -> a -> c -- | Identity function. -- --
--   id x = x
--   
id :: a -> a -- | <math>. map f xs is the list obtained by -- applying f to each element of xs, i.e., -- --
--   map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
--   map f [x1, x2, ...] == [f x1, f x2, ...]
--   
-- --
--   >>> map (+1) [1, 2, 3]
--   [2,3,4]
--   
map :: (a -> b) -> [a] -> [b] -- | otherwise is defined as the value True. It helps to make -- guards more readable. eg. -- --
--   f x | x < 0     = ...
--       | otherwise = ...
--   
otherwise :: Bool -- | until p f yields the result of applying f -- until p holds. until :: (a -> Bool) -> (a -> a) -> a -> a -- | Raise an IOException in the IO monad. ioError :: IOError -> IO a -- | Construct an IOException value with a string describing the -- error. The fail method of the IO instance of the -- Monad class raises a userError, thus: -- --
--   instance Monad IO where
--     ...
--     fail s = ioError (userError s)
--   
userError :: String -> IOError -- | List index (subscript) operator, starting from 0. It is an instance of -- the more general genericIndex, which takes an index of any -- integral type. -- --
--   >>> ['a', 'b', 'c'] !! 0
--   'a'
--   
--   >>> ['a', 'b', 'c'] !! 2
--   'c'
--   
--   >>> ['a', 'b', 'c'] !! 3
--   *** Exception: Prelude.!!: index too large
--   
--   >>> ['a', 'b', 'c'] !! (-1)
--   *** Exception: Prelude.!!: negative index
--   
-- -- WARNING: This function is partial. You can use atMay instead. (!!) :: HasCallStack => [a] -> Int -> a infixl 9 !! -- | break, applied to a predicate p and a list -- xs, returns a tuple where first element is longest prefix -- (possibly empty) of xs of elements that do not satisfy -- p and second element is the remainder of the list: -- --
--   >>> break (> 3) [1,2,3,4,1,2,3,4]
--   ([1,2,3],[4,1,2,3,4])
--   
--   >>> break (< 9) [1,2,3]
--   ([],[1,2,3])
--   
--   >>> break (> 9) [1,2,3]
--   ([1,2,3],[])
--   
-- -- break p is equivalent to span (not . -- p). break :: (a -> Bool) -> [a] -> ([a], [a]) -- | cycle ties a finite list into a circular one, or equivalently, -- the infinite repetition of the original list. It is the identity on -- infinite lists. -- --
--   >>> cycle []
--   *** Exception: Prelude.cycle: empty list
--   
--   >>> cycle [42]
--   [42,42,42,42,42,42,42,42,42,42...
--   
--   >>> cycle [2, 5, 7]
--   [2,5,7,2,5,7,2,5,7,2,5,7...
--   
cycle :: HasCallStack => [a] -> [a] -- | drop n xs returns the suffix of xs after the -- first n elements, or [] if n >= length -- xs. -- --
--   >>> drop 6 "Hello World!"
--   "World!"
--   
--   >>> drop 3 [1,2,3,4,5]
--   [4,5]
--   
--   >>> drop 3 [1,2]
--   []
--   
--   >>> drop 3 []
--   []
--   
--   >>> drop (-1) [1,2]
--   [1,2]
--   
--   >>> drop 0 [1,2]
--   [1,2]
--   
-- -- It is an instance of the more general genericDrop, in which -- n may be of any integral type. drop :: Int -> [a] -> [a] -- | dropWhile p xs returns the suffix remaining after -- takeWhile p xs. -- --
--   >>> dropWhile (< 3) [1,2,3,4,5,1,2,3]
--   [3,4,5,1,2,3]
--   
--   >>> dropWhile (< 9) [1,2,3]
--   []
--   
--   >>> dropWhile (< 0) [1,2,3]
--   [1,2,3]
--   
dropWhile :: (a -> Bool) -> [a] -> [a] -- | <math>. filter, applied to a predicate and a list, -- returns the list of those elements that satisfy the predicate; i.e., -- --
--   filter p xs = [ x | x <- xs, p x]
--   
-- --
--   >>> filter odd [1, 2, 3]
--   [1,3]
--   
filter :: (a -> Bool) -> [a] -> [a] -- | <math>. Extract the first element of a list, which must be -- non-empty. -- --
--   >>> head [1, 2, 3]
--   1
--   
--   >>> head [1..]
--   1
--   
--   >>> head []
--   *** Exception: Prelude.head: empty list
--   
-- -- WARNING: This function is partial. You can use case-matching, -- uncons or listToMaybe instead. head :: HasCallStack => [a] -> a -- | <math>. Return all the elements of a list except the last one. -- The list must be non-empty. -- --
--   >>> init [1, 2, 3]
--   [1,2]
--   
--   >>> init [1]
--   []
--   
--   >>> init []
--   *** Exception: Prelude.init: empty list
--   
-- -- WARNING: This function is partial. You can use reverse with -- case-matching or uncons instead. init :: HasCallStack => [a] -> [a] -- | iterate f x returns an infinite list of repeated -- applications of f to x: -- --
--   iterate f x == [x, f x, f (f x), ...]
--   
-- -- Note that iterate is lazy, potentially leading to thunk -- build-up if the consumer doesn't force each iterate. See -- iterate' for a strict variant of this function. -- --
--   >>> take 10 $ iterate not True
--   [True,False,True,False...
--   
--   >>> take 10 $ iterate (+3) 42
--   [42,45,48,51,54,57,60,63...
--   
iterate :: (a -> a) -> a -> [a] -- | <math>. Extract the last element of a list, which must be finite -- and non-empty. -- --
--   >>> last [1, 2, 3]
--   3
--   
--   >>> last [1..]
--   * Hangs forever *
--   
--   >>> last []
--   *** Exception: Prelude.last: empty list
--   
-- -- WARNING: This function is partial. You can use reverse with -- case-matching, uncons or listToMaybe instead. last :: HasCallStack => [a] -> a -- | <math>. lookup key assocs looks up a key in an -- association list. For the result to be Nothing, the list must -- be finite. -- --
--   >>> lookup 2 []
--   Nothing
--   
--   >>> lookup 2 [(1, "first")]
--   Nothing
--   
--   >>> lookup 2 [(1, "first"), (2, "second"), (3, "third")]
--   Just "second"
--   
lookup :: Eq a => a -> [(a, b)] -> Maybe b -- | repeat x is an infinite list, with x the -- value of every element. -- --
--   >>> repeat 17
--   [17,17,17,17,17,17,17,17,17...
--   
repeat :: a -> [a] -- | replicate n x is a list of length n with -- x the value of every element. It is an instance of the more -- general genericReplicate, in which n may be of any -- integral type. -- --
--   >>> replicate 0 True
--   []
--   
--   >>> replicate (-1) True
--   []
--   
--   >>> replicate 4 True
--   [True,True,True,True]
--   
replicate :: Int -> a -> [a] -- | reverse xs returns the elements of xs in -- reverse order. xs must be finite. -- --
--   >>> reverse []
--   []
--   
--   >>> reverse [42]
--   [42]
--   
--   >>> reverse [2,5,7]
--   [7,5,2]
--   
--   >>> reverse [1..]
--   * Hangs forever *
--   
reverse :: [a] -> [a] -- | <math>. scanl is similar to foldl, but returns a -- list 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 (+) 0 [1..4]
--   [0,1,3,6,10]
--   
--   >>> scanl (+) 42 []
--   [42]
--   
--   >>> scanl (-) 100 [1..4]
--   [100,99,97,94,90]
--   
--   >>> scanl (\reversedString nextChar -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["foo","afoo","bafoo","cbafoo","dcbafoo"]
--   
--   >>> scanl (+) 0 [1..]
--   * Hangs forever *
--   
scanl :: (b -> a -> b) -> b -> [a] -> [b] -- | <math>. scanl1 is a variant of scanl that has no -- starting value argument: -- --
--   scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
--   
-- --
--   >>> scanl1 (+) [1..4]
--   [1,3,6,10]
--   
--   >>> scanl1 (+) []
--   []
--   
--   >>> scanl1 (-) [1..4]
--   [1,-1,-4,-8]
--   
--   >>> scanl1 (&&) [True, False, True, True]
--   [True,False,False,False]
--   
--   >>> scanl1 (||) [False, False, True, True]
--   [False,False,True,True]
--   
--   >>> scanl1 (+) [1..]
--   * Hangs forever *
--   
scanl1 :: (a -> a -> a) -> [a] -> [a] -- | <math>. scanr is the right-to-left dual of scanl. -- Note that the order of parameters on the accumulating function are -- reversed compared to scanl. Also note that -- --
--   head (scanr f z xs) == foldr f z xs.
--   
-- --
--   >>> scanr (+) 0 [1..4]
--   [10,9,7,4,0]
--   
--   >>> scanr (+) 42 []
--   [42]
--   
--   >>> scanr (-) 100 [1..4]
--   [98,-97,99,-96,100]
--   
--   >>> scanr (\nextChar reversedString -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']
--   ["abcdfoo","bcdfoo","cdfoo","dfoo","foo"]
--   
--   >>> force $ scanr (+) 0 [1..]
--   *** Exception: stack overflow
--   
scanr :: (a -> b -> b) -> b -> [a] -> [b] -- | <math>. scanr1 is a variant of scanr that has no -- starting value argument. -- --
--   >>> scanr1 (+) [1..4]
--   [10,9,7,4]
--   
--   >>> scanr1 (+) []
--   []
--   
--   >>> scanr1 (-) [1..4]
--   [-2,3,-1,4]
--   
--   >>> scanr1 (&&) [True, False, True, True]
--   [False,False,True,True]
--   
--   >>> scanr1 (||) [True, True, False, False]
--   [True,True,False,False]
--   
--   >>> force $ scanr1 (+) [1..]
--   *** Exception: stack overflow
--   
scanr1 :: (a -> a -> a) -> [a] -> [a] -- | span, applied to a predicate p and a list xs, -- returns a tuple where first element is longest prefix (possibly empty) -- of xs of elements that satisfy p and second element -- is the remainder of the list: -- --
--   >>> span (< 3) [1,2,3,4,1,2,3,4]
--   ([1,2],[3,4,1,2,3,4])
--   
--   >>> span (< 9) [1,2,3]
--   ([1,2,3],[])
--   
--   >>> span (< 0) [1,2,3]
--   ([],[1,2,3])
--   
-- -- span p xs is equivalent to (takeWhile p xs, -- dropWhile p xs) span :: (a -> Bool) -> [a] -> ([a], [a]) -- | splitAt n xs returns a tuple where first element is -- xs prefix of length n and second element is the -- remainder of the list: -- --
--   >>> splitAt 6 "Hello World!"
--   ("Hello ","World!")
--   
--   >>> splitAt 3 [1,2,3,4,5]
--   ([1,2,3],[4,5])
--   
--   >>> splitAt 1 [1,2,3]
--   ([1],[2,3])
--   
--   >>> splitAt 3 [1,2,3]
--   ([1,2,3],[])
--   
--   >>> splitAt 4 [1,2,3]
--   ([1,2,3],[])
--   
--   >>> splitAt 0 [1,2,3]
--   ([],[1,2,3])
--   
--   >>> splitAt (-1) [1,2,3]
--   ([],[1,2,3])
--   
-- -- It is equivalent to (take n xs, drop n xs) when -- n is not _|_ (splitAt _|_ xs = _|_). -- splitAt is an instance of the more general -- genericSplitAt, in which n may be of any integral -- type. splitAt :: Int -> [a] -> ([a], [a]) -- | <math>. Extract the elements after the head of a list, which -- must be non-empty. -- --
--   >>> tail [1, 2, 3]
--   [2,3]
--   
--   >>> tail [1]
--   []
--   
--   >>> tail []
--   *** Exception: Prelude.tail: empty list
--   
-- -- WARNING: This function is partial. You can use case-matching or -- uncons instead. tail :: HasCallStack => [a] -> [a] -- | take n, applied to a list xs, returns the -- prefix of xs of length n, or xs itself if -- n >= length xs. -- --
--   >>> take 5 "Hello World!"
--   "Hello"
--   
--   >>> take 3 [1,2,3,4,5]
--   [1,2,3]
--   
--   >>> take 3 [1,2]
--   [1,2]
--   
--   >>> take 3 []
--   []
--   
--   >>> take (-1) [1,2]
--   []
--   
--   >>> take 0 [1,2]
--   []
--   
-- -- It is an instance of the more general genericTake, in which -- n may be of any integral type. take :: Int -> [a] -> [a] -- | takeWhile, applied to a predicate p and a list -- xs, returns the longest prefix (possibly empty) of -- xs of elements that satisfy p. -- --
--   >>> takeWhile (< 3) [1,2,3,4,1,2,3,4]
--   [1,2]
--   
--   >>> takeWhile (< 9) [1,2,3]
--   [1,2,3]
--   
--   >>> takeWhile (< 0) [1,2,3]
--   []
--   
takeWhile :: (a -> Bool) -> [a] -> [a] -- | unzip transforms a list of pairs into a list of first -- components and a list of second components. -- --
--   >>> unzip []
--   ([],[])
--   
--   >>> unzip [(1, 'a'), (2, 'b')]
--   ([1,2],"ab")
--   
unzip :: [(a, b)] -> ([a], [b]) -- | The unzip3 function takes a list of triples and returns three -- lists, analogous to unzip. -- --
--   >>> unzip3 []
--   ([],[],[])
--   
--   >>> unzip3 [(1, 'a', True), (2, 'b', False)]
--   ([1,2],"ab",[True,False])
--   
unzip3 :: [(a, b, c)] -> ([a], [b], [c]) -- | <math>. zip takes two lists and returns a list of -- corresponding pairs. -- --
--   >>> zip [1, 2] ['a', 'b']
--   [(1,'a'),(2,'b')]
--   
-- -- If one input list is shorter than the other, excess elements of the -- longer list are discarded, even if one of the lists is infinite: -- --
--   >>> zip [1] ['a', 'b']
--   [(1,'a')]
--   
--   >>> zip [1, 2] ['a']
--   [(1,'a')]
--   
--   >>> zip [] [1..]
--   []
--   
--   >>> zip [1..] []
--   []
--   
-- -- zip is right-lazy: -- --
--   >>> zip [] undefined
--   []
--   
--   >>> zip undefined []
--   *** Exception: Prelude.undefined
--   ...
--   
-- -- zip is capable of list fusion, but it is restricted to its -- first list argument and its resulting list. zip :: [a] -> [b] -> [(a, b)] -- | zip3 takes three lists and returns a list of triples, analogous -- to zip. It is capable of list fusion, but it is restricted to -- its first list argument and its resulting list. zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] -- | <math>. zipWith generalises zip by zipping with -- the function given as the first argument, instead of a tupling -- function. -- --
--   zipWith (,) xs ys == zip xs ys
--   zipWith f [x1,x2,x3..] [y1,y2,y3..] == [f x1 y1, f x2 y2, f x3 y3..]
--   
-- -- For example, zipWith (+) is applied to two lists to -- produce the list of corresponding sums: -- --
--   >>> zipWith (+) [1, 2, 3] [4, 5, 6]
--   [5,7,9]
--   
-- -- zipWith is right-lazy: -- --
--   >>> let f = undefined
--   
--   >>> zipWith f [] undefined
--   []
--   
-- -- zipWith is capable of list fusion, but it is restricted to its -- first list argument and its resulting list. zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] -- | The zipWith3 function takes a function which combines three -- elements, as well as three lists and returns a list of the function -- applied to corresponding elements, analogous to zipWith. It is -- capable of list fusion, but it is restricted to its first list -- argument and its resulting list. -- --
--   zipWith3 (,,) xs ys zs == zip3 xs ys zs
--   zipWith3 f [x1,x2,x3..] [y1,y2,y3..] [z1,z2,z3..] == [f x1 y1 z1, f x2 y2 z2, f x3 y3 z3..]
--   
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d] -- | the same as flip (-). -- -- Because - is treated specially in the Haskell grammar, -- (- e) is not a section, but an application of -- prefix negation. However, (subtract -- exp) is equivalent to the disallowed section. subtract :: Num a => a -> a -> a -- | The lex function reads a single lexeme from the input, -- discarding initial white space, and returning the characters that -- constitute the lexeme. If the input string contains only white space, -- lex returns a single successful `lexeme' consisting of the -- empty string. (Thus lex "" = [("","")].) If there is -- no legal lexeme at the beginning of the input string, lex fails -- (i.e. returns []). -- -- This lexer is not completely faithful to the Haskell lexical syntax in -- the following respects: -- -- lex :: ReadS String -- | readParen True p parses what p parses, -- but surrounded with parentheses. -- -- readParen False p parses what p -- parses, but optionally surrounded with parentheses. readParen :: Bool -> ReadS a -> ReadS a -- | raise a number to a non-negative integral power (^) :: (Num a, Integral b) => a -> b -> a infixr 8 ^ -- | raise a number to an integral power (^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 ^^ even :: Integral a => a -> Bool -- | General coercion from Integral types. -- -- WARNING: This function performs silent truncation if the result type -- is not at least as big as the argument's type. fromIntegral :: (Integral a, Num b) => a -> b -- | gcd x y is the non-negative factor of both x -- and y of which every common factor of x and -- y is also a factor; for example gcd 4 2 = 2, -- gcd (-4) 6 = 2, gcd 0 4 = 4. -- gcd 0 0 = 0. (That is, the common divisor -- that is "greatest" in the divisibility preordering.) -- -- Note: Since for signed fixed-width integer types, abs -- minBound < 0, the result may be negative if one of the -- arguments is minBound (and necessarily is if the other -- is 0 or minBound) for such types. gcd :: Integral a => a -> a -> a -- | lcm x y is the smallest positive integer that both -- x and y divide. lcm :: Integral a => a -> a -> a odd :: Integral a => a -> Bool -- | General coercion to Fractional types. -- -- WARNING: This function goes through the Rational type, which -- does not have values for NaN for example. This means it does -- not round-trip. -- -- For Double it also behaves differently with or without -O0: -- --
--   Prelude> realToFrac nan -- With -O0
--   -Infinity
--   Prelude> realToFrac nan
--   NaN
--   
realToFrac :: (Real a, Fractional b) => a -> b -- | utility function converting a Char to a show function that -- simply prepends the character unchanged. showChar :: Char -> ShowS -- | utility function that surrounds the inner show function with -- parentheses when the Bool parameter is True. showParen :: Bool -> ShowS -> ShowS -- | utility function converting a String to a show function that -- simply prepends the string unchanged. showString :: String -> ShowS -- | equivalent to showsPrec with a precedence of 0. shows :: Show a => a -> ShowS -- | The computation appendFile file str function appends -- the string str, to the file file. -- -- Note that writeFile and appendFile write a literal -- string to a file. To write a value of any printable type, as with -- print, use the show function to convert the value to a -- string first. -- --
--   main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]])
--   
appendFile :: FilePath -> String -> IO () -- | Read a character from the standard input device (same as -- hGetChar stdin). getChar :: IO Char -- | The getContents operation returns all user input as a single -- string, which is read lazily as it is needed (same as -- hGetContents stdin). getContents :: IO String -- | Read a line from the standard input device (same as hGetLine -- stdin). getLine :: IO String -- | The interact function takes a function of type -- String->String as its argument. The entire input from the -- standard input device is passed to this function as its argument, and -- the resulting string is output on the standard output device. interact :: (String -> String) -> IO () -- | The print function outputs a value of any printable type to the -- standard output device. Printable types are those that are instances -- of class Show; print converts values to strings for -- output using the show operation and adds a newline. -- -- For example, a program to print the first 20 integers and their powers -- of 2 could be written as: -- --
--   main = print ([(n, 2^n) | n <- [0..19]])
--   
print :: Show a => a -> IO () -- | Write a character to the standard output device (same as -- hPutChar stdout). putChar :: Char -> IO () -- | Write a string to the standard output device (same as hPutStr -- stdout). putStr :: String -> IO () -- | The same as putStr, but adds a newline character. putStrLn :: String -> IO () -- | The readFile function reads a file and returns the contents of -- the file as a string. The file is read lazily, on demand, as with -- getContents. readFile :: FilePath -> IO String -- | The readIO function is similar to read except that it -- signals parse failure to the IO monad instead of terminating -- the program. readIO :: Read a => String -> IO a -- | The readLn function combines getLine and readIO. readLn :: Read a => IO a -- | The computation writeFile file str function writes the -- string str, to the file file. writeFile :: FilePath -> String -> IO () -- | The read function reads input from a string, which must be -- completely consumed by the input process. read fails with an -- error if the parse is unsuccessful, and it is therefore -- discouraged from being used in real applications. Use readMaybe -- or readEither for safe alternatives. -- --
--   >>> read "123" :: Int
--   123
--   
-- --
--   >>> read "hello" :: Int
--   *** Exception: Prelude.read: no parse
--   
read :: Read a => String -> a -- | equivalent to readsPrec with a precedence of 0. reads :: Read a => ReadS a -- | Boolean "and", lazy in the second argument (&&) :: Bool -> Bool -> Bool infixr 3 && -- | Boolean "not" not :: Bool -> Bool -- | Boolean "or", lazy in the second argument (||) :: Bool -> Bool -> Bool infixr 2 || -- | Application operator. This operator is redundant, since ordinary -- application (f x) means the same as (f $ x). -- However, $ has low, right-associative binding precedence, so it -- sometimes allows parentheses to be omitted; for example: -- --
--   f $ g $ h x  =  f (g (h x))
--   
-- -- It is also useful in higher-order situations, such as map -- ($ 0) xs, or zipWith ($) fs xs. -- -- Note that ($) is representation-polymorphic in its -- result type, so that foo $ True where foo :: Bool -- -> Int# is well-typed. ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 $ -- | error stops execution and displays an error message. error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] -> a -- | A variant of error that does not produce a stack trace. errorWithoutStackTrace :: forall (r :: RuntimeRep) (a :: TYPE r). [Char] -> a -- | A special case of error. It is expected that compilers will -- recognize this and insert error messages which are more appropriate to -- the context in which undefined appears. undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a -- | The value of seq a b is bottom if a is -- bottom, and otherwise equal to b. In other words, it -- evaluates the first argument a to weak head normal form -- (WHNF). seq is usually introduced to improve performance by -- avoiding unneeded laziness. -- -- A note on evaluation order: the expression seq a b -- does not guarantee that a will be evaluated before -- b. The only guarantee given by seq is that the both -- a and b will be evaluated before seq returns -- a value. In particular, this means that b may be evaluated -- before a. If you need to guarantee a specific order of -- evaluation, you must use the function pseq from the -- "parallel" package. seq :: forall {r :: RuntimeRep} a (b :: TYPE r). a -> b -> b infixr 0 `seq` -- | Does the element occur in the structure? -- -- Note: elem is often used in infix form. -- --

Examples

-- -- Basic usage: -- --
--   >>> 3 `elem` []
--   False
--   
-- --
--   >>> 3 `elem` [1,2]
--   False
--   
-- --
--   >>> 3 `elem` [1,2,3,4,5]
--   True
--   
-- -- For infinite structures, the default implementation of elem -- terminates if the sought-after value exists at a finite distance from -- the left side of the structure: -- --
--   >>> 3 `elem` [1..]
--   True
--   
-- --
--   >>> 3 `elem` ([4..] ++ [3])
--   * Hangs forever *
--   
elem :: (Foldable t, Eq a) => a -> t a -> Bool infix 4 `elem` -- | Map each element of the structure into a monoid, and combine the -- results with (<>). This fold is -- right-associative and lazy in the accumulator. For strict -- left-associative folds consider foldMap' instead. -- --

Examples

-- -- Basic usage: -- --
--   >>> foldMap Sum [1, 3, 5]
--   Sum {getSum = 9}
--   
-- --
--   >>> foldMap Product [1, 3, 5]
--   Product {getProduct = 15}
--   
-- --
--   >>> foldMap (replicate 3) [1, 2, 3]
--   [1,1,1,2,2,2,3,3,3]
--   
-- -- When a Monoid's (<>) is lazy in its second -- argument, foldMap can return a result even from an unbounded -- structure. For example, lazy accumulation enables -- Data.ByteString.Builder to efficiently serialise large data -- structures and produce the output incrementally: -- --
--   >>> import qualified Data.ByteString.Lazy as L
--   
--   >>> import qualified Data.ByteString.Builder as B
--   
--   >>> let bld :: Int -> B.Builder; bld i = B.intDec i <> B.word8 0x20
--   
--   >>> let lbs = B.toLazyByteString $ foldMap bld [0..]
--   
--   >>> L.take 64 lbs
--   "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24"
--   
foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m -- | Left-associative fold of a structure, lazy in the accumulator. This is -- rarely what you want, but can work well for structures with efficient -- right-to-left sequencing and an operator that is lazy in its left -- argument. -- -- In the case of lists, foldl, when applied to a binary operator, -- a starting value (typically the left-identity of the operator), and a -- list, reduces the list using the binary operator, from left to right: -- --
--   foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
--   
-- -- Note that to produce the outermost application of the operator the -- entire input list must be traversed. Like all left-associative folds, -- foldl will diverge if given an infinite list. -- -- If you want an efficient strict left-fold, you probably want to use -- foldl' instead of foldl. The reason for this is that the -- latter does not force the inner results (e.g. z `f` x1 -- in the above example) before applying them to the operator (e.g. to -- (`f` x2)). This results in a thunk chain O(n) elements -- long, which then must be evaluated from the outside-in. -- -- For a general Foldable structure this should be semantically -- identical to: -- --
--   foldl f z = foldl f z . toList
--   
-- --

Examples

-- -- The first example is a strict fold, which in practice is best -- performed with foldl'. -- --
--   >>> foldl (+) 42 [1,2,3,4]
--   52
--   
-- -- Though the result below is lazy, the input is reversed before -- prepending it to the initial accumulator, so corecursion begins only -- after traversing the entire input string. -- --
--   >>> foldl (\acc c -> c : acc) "abcd" "efgh"
--   "hgfeabcd"
--   
-- -- A left fold of a structure that is infinite on the right cannot -- terminate, even when for any finite input the fold just returns the -- initial accumulator: -- --
--   >>> foldl (\a _ -> a) 0 $ repeat 1
--   * Hangs forever *
--   
-- -- WARNING: When it comes to lists, you always want to use either -- foldl' or foldr instead. foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | Left-associative fold of a structure but with strict application of -- the operator. -- -- This ensures that each step of the fold is forced to Weak Head Normal -- Form before being applied, avoiding the collection of thunks that -- would otherwise occur. This is often what you want to strictly reduce -- a finite structure to a single strict result (e.g. sum). -- -- For a general Foldable structure this should be semantically -- identical to, -- --
--   foldl' f z = foldl' f z . toList
--   
foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b -- | A variant of foldl that has no base case, and thus may only be -- applied to non-empty structures. -- -- This function is non-total and will raise a runtime exception if the -- structure happens to be empty. -- --
--   foldl1 f = foldl1 f . toList
--   
-- --

Examples

-- -- Basic usage: -- --
--   >>> foldl1 (+) [1..4]
--   10
--   
-- --
--   >>> foldl1 (+) []
--   *** Exception: Prelude.foldl1: empty list
--   
-- --
--   >>> foldl1 (+) Nothing
--   *** Exception: foldl1: empty structure
--   
-- --
--   >>> foldl1 (-) [1..4]
--   -8
--   
-- --
--   >>> foldl1 (&&) [True, False, True, True]
--   False
--   
-- --
--   >>> foldl1 (||) [False, False, True, True]
--   True
--   
-- --
--   >>> foldl1 (+) [1..]
--   * Hangs forever *
--   
foldl1 :: Foldable t => (a -> a -> a) -> t a -> a -- | Right-associative fold of a structure, lazy in the accumulator. -- -- In the case of lists, foldr, when applied to a binary operator, -- a starting value (typically the right-identity of the operator), and a -- list, reduces the list using the binary operator, from right to left: -- --
--   foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
--   
-- -- Note that since the head of the resulting expression is produced by an -- application of the operator to the first element of the list, given an -- operator lazy in its right argument, foldr can produce a -- terminating expression from an unbounded list. -- -- For a general Foldable structure this should be semantically -- identical to, -- --
--   foldr f z = foldr f z . toList
--   
-- --

Examples

-- -- Basic usage: -- --
--   >>> foldr (||) False [False, True, False]
--   True
--   
-- --
--   >>> foldr (||) False []
--   False
--   
-- --
--   >>> foldr (\c acc -> acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
--   "foodcba"
--   
-- --
Infinite structures
-- -- ⚠️ Applying foldr to infinite structures usually doesn't -- terminate. -- -- It may still terminate under one of the following conditions: -- -- -- --
Short-circuiting
-- -- (||) short-circuits on True values, so the -- following terminates because there is a True value finitely far -- from the left side: -- --
--   >>> foldr (||) False (True : repeat False)
--   True
--   
-- -- But the following doesn't terminate: -- --
--   >>> foldr (||) False (repeat False ++ [True])
--   * Hangs forever *
--   
-- --
Laziness in the second argument
-- -- Applying foldr to infinite structures terminates when the -- operator is lazy in its second argument (the initial accumulator is -- never used in this case, and so could be left undefined, but -- [] is more clear): -- --
--   >>> take 5 $ foldr (\i acc -> i : fmap (+3) acc) [] (repeat 1)
--   [1,4,7,10,13]
--   
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b -- | A variant of foldr that has no base case, and thus may only be -- applied to non-empty structures. -- -- This function is non-total and will raise a runtime exception if the -- structure happens to be empty. -- --

Examples

-- -- Basic usage: -- --
--   >>> foldr1 (+) [1..4]
--   10
--   
-- --
--   >>> foldr1 (+) []
--   Exception: Prelude.foldr1: empty list
--   
-- --
--   >>> foldr1 (+) Nothing
--   *** Exception: foldr1: empty structure
--   
-- --
--   >>> foldr1 (-) [1..4]
--   -2
--   
-- --
--   >>> foldr1 (&&) [True, False, True, True]
--   False
--   
-- --
--   >>> foldr1 (||) [False, False, True, True]
--   True
--   
-- --
--   >>> foldr1 (+) [1..]
--   * Hangs forever *
--   
foldr1 :: Foldable t => (a -> a -> a) -> t a -> a -- | Returns the size/length of a finite structure as an Int. The -- default implementation just counts elements starting with the -- leftmost. Instances for structures that can compute the element count -- faster than via element-by-element counting, should provide a -- specialised implementation. -- --

Examples

-- -- Basic usage: -- --
--   >>> length []
--   0
--   
-- --
--   >>> length ['a', 'b', 'c']
--   3
--   
--   >>> length [1..]
--   * Hangs forever *
--   
length :: Foldable t => t a -> Int -- | The largest element of a non-empty structure. -- -- This function is non-total and will raise a runtime exception if the -- structure happens to be empty. A structure that supports random access -- and maintains its elements in order should provide a specialised -- implementation to return the maximum in faster than linear time. -- --

Examples

-- -- Basic usage: -- --
--   >>> maximum [1..10]
--   10
--   
-- --
--   >>> maximum []
--   *** Exception: Prelude.maximum: empty list
--   
-- --
--   >>> maximum Nothing
--   *** Exception: maximum: empty structure
--   
-- -- WARNING: This function is partial for possibly-empty structures like -- lists. maximum :: (Foldable t, Ord a) => t a -> a -- | The least element of a non-empty structure. -- -- This function is non-total and will raise a runtime exception if the -- structure happens to be empty. A structure that supports random access -- and maintains its elements in order should provide a specialised -- implementation to return the minimum in faster than linear time. -- --

Examples

-- -- Basic usage: -- --
--   >>> minimum [1..10]
--   1
--   
-- --
--   >>> minimum []
--   *** Exception: Prelude.minimum: empty list
--   
-- --
--   >>> minimum Nothing
--   *** Exception: minimum: empty structure
--   
-- -- WARNING: This function is partial for possibly-empty structures like -- lists. minimum :: (Foldable t, Ord a) => t a -> a -- | Test whether the structure is empty. The default implementation is -- Left-associative and lazy in both the initial element and the -- accumulator. Thus optimised for structures where the first element can -- be accessed in constant time. Structures where this is not the case -- should have a non-default implementation. -- --

Examples

-- -- Basic usage: -- --
--   >>> null []
--   True
--   
-- --
--   >>> null [1]
--   False
--   
-- -- null is expected to terminate even for infinite structures. The -- default implementation terminates provided the structure is bounded on -- the left (there is a leftmost element). -- --
--   >>> null [1..]
--   False
--   
null :: Foldable t => t a -> Bool -- | The product function computes the product of the numbers of a -- structure. -- --

Examples

-- -- Basic usage: -- --
--   >>> product []
--   1
--   
-- --
--   >>> product [42]
--   42
--   
-- --
--   >>> product [1..10]
--   3628800
--   
-- --
--   >>> product [4.1, 2.0, 1.7]
--   13.939999999999998
--   
-- --
--   >>> product [1..]
--   * Hangs forever *
--   
product :: (Foldable t, Num a) => t a -> a -- | The sum function computes the sum of the numbers of a -- structure. -- --

Examples

-- -- Basic usage: -- --
--   >>> sum []
--   0
--   
-- --
--   >>> sum [42]
--   42
--   
-- --
--   >>> sum [1..10]
--   55
--   
-- --
--   >>> sum [4.1, 2.0, 1.7]
--   7.8
--   
-- --
--   >>> sum [1..]
--   * Hangs forever *
--   
sum :: (Foldable t, Num a) => t a -> a -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and collect the results. For a version -- that ignores the results see mapM_. -- --

Examples

-- -- mapM is literally a traverse with a type signature -- restricted to Monad. Its implementation may be more efficient -- due to additional power of Monad. mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) -- | Evaluate each monadic action in the structure from left to right, and -- collect the results. For a version that ignores the results see -- sequence_. -- --

Examples

-- -- Basic usage: -- -- The first two examples are instances where the input and and output of -- sequence are isomorphic. -- --
--   >>> sequence $ Right [1,2,3,4]
--   [Right 1,Right 2,Right 3,Right 4]
--   
-- --
--   >>> sequence $ [Right 1,Right 2,Right 3,Right 4]
--   Right [1,2,3,4]
--   
-- -- The following examples demonstrate short circuit behavior for -- sequence. -- --
--   >>> sequence $ Left [1,2,3,4]
--   Left [1,2,3,4]
--   
-- --
--   >>> sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
--   Left 0
--   
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) -- | Evaluate each action in the structure from left to right, and collect -- the results. For a version that ignores the results see -- sequenceA_. -- --

Examples

-- -- Basic usage: -- -- For the first two examples we show sequenceA fully evaluating a a -- structure and collecting the results. -- --
--   >>> sequenceA [Just 1, Just 2, Just 3]
--   Just [1,2,3]
--   
-- --
--   >>> sequenceA [Right 1, Right 2, Right 3]
--   Right [1,2,3]
--   
-- -- The next two example show Nothing and Just will short -- circuit the resulting structure if present in the input. For more -- context, check the Traversable instances for Either and -- Maybe. -- --
--   >>> sequenceA [Just 1, Just 2, Just 3, Nothing]
--   Nothing
--   
-- --
--   >>> sequenceA [Right 1, Right 2, Right 3, Left 4]
--   Left 4
--   
sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a) -- | Map each element of a structure to an action, evaluate these actions -- from left to right, and collect the results. For a version that -- ignores the results see traverse_. -- --

Examples

-- -- Basic usage: -- -- In the first two examples we show each evaluated action mapping to the -- output structure. -- --
--   >>> traverse Just [1,2,3,4]
--   Just [1,2,3,4]
--   
-- --
--   >>> traverse id [Right 1, Right 2, Right 3, Right 4]
--   Right [1,2,3,4]
--   
-- -- In the next examples, we show that Nothing and Left -- values short circuit the created structure. -- --
--   >>> traverse (const Nothing) [1,2,3,4]
--   Nothing
--   
-- --
--   >>> traverse (\x -> if odd x then Just x else Nothing)  [1,2,3,4]
--   Nothing
--   
-- --
--   >>> traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]
--   Left 0
--   
traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b) -- | Sequence actions, discarding the value of the first argument. -- --

Examples

-- -- If used in conjunction with the Applicative instance for Maybe, -- you can chain Maybe computations, with a possible "early return" in -- case of Nothing. -- --
--   >>> Just 2 *> Just 3
--   Just 3
--   
-- --
--   >>> Nothing *> Just 3
--   Nothing
--   
-- -- Of course a more interesting use case would be to have effectful -- computations instead of just returning pure values. -- --
--   >>> import Data.Char
--   
--   >>> import Text.ParserCombinators.ReadP
--   
--   >>> let p = string "my name is " *> munch1 isAlpha <* eof
--   
--   >>> readP_to_S p "my name is Simon"
--   [("Simon","")]
--   
(*>) :: Applicative f => f a -> f b -> f b infixl 4 *> -- | Sequence actions, discarding the value of the second argument. (<*) :: Applicative f => f a -> f b -> f a infixl 4 <* -- | Sequential application. -- -- A few functors support an implementation of <*> that is -- more efficient than the default one. -- --

Example

-- -- Used in combination with (<$>), -- (<*>) can be used to build a record. -- --
--   >>> data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
--   
-- --
--   >>> produceFoo :: Applicative f => f Foo
--   
-- --
--   >>> produceBar :: Applicative f => f Bar
--   
--   >>> produceBaz :: Applicative f => f Baz
--   
-- --
--   >>> mkState :: Applicative f => f MyState
--   
--   >>> mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
--   
(<*>) :: Applicative f => f (a -> b) -> f a -> f b infixl 4 <*> -- | Lift a value. pure :: Applicative f => a -> f a -- | Lift a binary function to actions. -- -- Some functors support an implementation of liftA2 that is more -- efficient than the default one. In particular, if fmap is an -- expensive operation, it is likely better to use liftA2 than to -- fmap over the structure and then use <*>. -- -- This became a typeclass method in 4.10.0.0. Prior to that, it was a -- function defined in terms of <*> and fmap. -- --

Example

-- --
--   >>> liftA2 (,) (Just 3) (Just 5)
--   Just (3,5)
--   
liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c -- | Replace all locations in the input with the same value. The default -- definition is fmap . const, but this may be -- overridden with a more efficient version. -- --

Examples

-- -- Perform a computation with Maybe and replace the result with a -- constant value if it is Just: -- --
--   >>> 'a' <$ Just 2
--   Just 'a'
--   
--   >>> 'a' <$ Nothing
--   Nothing
--   
(<$) :: Functor f => a -> f b -> f a infixl 4 <$ -- | fmap is used to apply a function of type (a -> b) -- to a value of type f a, where f is a functor, to produce a -- value of type f b. Note that for any type constructor with -- more than one parameter (e.g., Either), only the last type -- parameter can be modified with fmap (e.g., b in -- `Either a b`). -- -- Some type constructors with two parameters or more have a -- Bifunctor instance that allows both the last and the -- penultimate parameters to be mapped over. -- --

Examples

-- -- Convert from a Maybe Int to a Maybe String -- using show: -- --
--   >>> fmap show Nothing
--   Nothing
--   
--   >>> fmap show (Just 3)
--   Just "3"
--   
-- -- Convert from an Either Int Int to an Either Int -- String using show: -- --
--   >>> fmap show (Left 17)
--   Left 17
--   
--   >>> fmap show (Right 17)
--   Right "17"
--   
-- -- Double each element of a list: -- --
--   >>> fmap (*2) [1,2,3]
--   [2,4,6]
--   
-- -- Apply even to the second element of a pair: -- --
--   >>> fmap even (2,2)
--   (2,True)
--   
-- -- It may seem surprising that the function is only applied to the last -- element of the tuple compared to the list example above which applies -- it to every element in the list. To understand, remember that tuples -- are type constructors with multiple type parameters: a tuple of 3 -- elements (a,b,c) can also be written (,,) a b c and -- its Functor instance is defined for Functor ((,,) a -- b) (i.e., only the third parameter is free to be mapped over with -- fmap). -- -- It explains why fmap can be used with tuples containing -- values of different types as in the following example: -- --
--   >>> fmap even ("hello", 1.0, 4)
--   ("hello",1.0,True)
--   
fmap :: Functor f => (a -> b) -> f a -> f b -- | Sequentially compose two actions, discarding any value produced by the -- first, like sequencing operators (such as the semicolon) in imperative -- languages. -- -- 'as >> bs' can be understood as the do -- expression -- --
--   do as
--      bs
--   
(>>) :: Monad m => m a -> m b -> m b infixl 1 >> -- | Sequentially compose two actions, passing any value produced by the -- first as an argument to the second. -- -- 'as >>= bs' can be understood as the do -- expression -- --
--   do a <- as
--      bs a
--   
(>>=) :: Monad m => m a -> (a -> m b) -> m b infixl 1 >>= fail :: MonadFail m => String -> m a -- | Inject a value into the monadic type. return :: Monad m => a -> m a -- | An associative operation -- -- NOTE: This method is redundant and has the default -- implementation mappend = (<>) since -- base-4.11.0.0. Should it be implemented manually, since -- mappend is a synonym for (<>), it is expected that -- the two functions are defined the same way. In a future GHC release -- mappend will be removed from Monoid. mappend :: Monoid a => a -> a -> a -- | Fold a list using the monoid. -- -- For most types, the default definition for mconcat will be -- used, but the function is included in the class definition so that an -- optimized version can be provided for specific types. -- --
--   >>> mconcat ["Hello", " ", "Haskell", "!"]
--   "Hello Haskell!"
--   
mconcat :: Monoid a => [a] -> a -- | Identity of mappend -- --
--   >>> "Hello world" <> mempty
--   "Hello world"
--   
mempty :: Monoid a => a -- | An associative operation. -- --
--   >>> [1,2,3] <> [4,5,6]
--   [1,2,3,4,5,6]
--   
(<>) :: Semigroup a => a -> a -> a infixr 6 <> maxBound :: Bounded a => a minBound :: Bounded a => a -- | Used in Haskell's translation of [n..] with [n..] = -- enumFrom n, a possible implementation being enumFrom n = n : -- enumFrom (succ n). For example: -- -- enumFrom :: Enum a => a -> [a] -- | Used in Haskell's translation of [n,n'..] with [n,n'..] = -- enumFromThen n n', a possible implementation being -- enumFromThen n n' = n : n' : worker (f x) (f x n'), -- worker s v = v : worker s (s v), x = fromEnum n' - -- fromEnum n and f n y | n > 0 = f (n - 1) (succ y) | n < -- 0 = f (n + 1) (pred y) | otherwise = y For example: -- -- enumFromThen :: Enum a => a -> a -> [a] -- | Used in Haskell's translation of [n,n'..m] with [n,n'..m] -- = enumFromThenTo n n' m, a possible implementation being -- enumFromThenTo n n' m = worker (f x) (c x) n m, x = -- fromEnum n' - fromEnum n, c x = bool (>=) ((x -- 0) f n y | n > 0 = f (n - 1) (succ y) | n < 0 = f (n + -- 1) (pred y) | otherwise = y and worker s c v m | c v m = v : -- worker s c (s v) m | otherwise = [] For example: -- -- enumFromThenTo :: Enum a => a -> a -> a -> [a] -- | Used in Haskell's translation of [n..m] with [n..m] = -- enumFromTo n m, a possible implementation being enumFromTo n -- m | n <= m = n : enumFromTo (succ n) m | otherwise = []. For -- example: -- -- enumFromTo :: Enum a => a -> a -> [a] -- | Convert to an Int. It is implementation-dependent what -- fromEnum returns when applied to a value that is too large to -- fit in an Int. fromEnum :: Enum a => a -> Int -- | the predecessor of a value. For numeric types, pred subtracts -- 1. pred :: Enum a => a -> a -- | the successor of a value. For numeric types, succ adds 1. succ :: Enum a => a -> a -- | Convert from an Int. toEnum :: Enum a => Int -> a (**) :: Floating a => a -> a -> a infixr 8 ** acos :: Floating a => a -> a acosh :: Floating a => a -> a asin :: Floating a => a -> a asinh :: Floating a => a -> a atan :: Floating a => a -> a atanh :: Floating a => a -> a cos :: Floating a => a -> a cosh :: Floating a => a -> a exp :: Floating a => a -> a log :: Floating a => a -> a logBase :: Floating a => a -> a -> a pi :: Floating a => a sin :: Floating a => a -> a sinh :: Floating a => a -> a sqrt :: Floating a => a -> a tan :: Floating a => a -> a tanh :: Floating a => a -> a -- | a version of arctangent taking two real floating-point arguments. For -- real floating x and y, atan2 y x -- computes the angle (from the positive x-axis) of the vector from the -- origin to the point (x,y). atan2 y x returns -- a value in the range [-pi, pi]. It follows the -- Common Lisp semantics for the origin when signed zeroes are supported. -- atan2 y 1, with y in a type that is -- RealFloat, should return the same value as atan -- y. A default definition of atan2 is provided, but -- implementors can provide a more accurate implementation. atan2 :: RealFloat a => a -> a -> a -- | The function decodeFloat applied to a real floating-point -- number returns the significand expressed as an Integer and an -- appropriately scaled exponent (an Int). If -- decodeFloat x yields (m,n), then x -- is equal in value to m*b^^n, where b is the -- floating-point radix, and furthermore, either m and -- n are both zero or else b^(d-1) <= abs m < -- b^d, where d is the value of floatDigits -- x. In particular, decodeFloat 0 = (0,0). If the -- type contains a negative zero, also decodeFloat (-0.0) = -- (0,0). The result of decodeFloat x is -- unspecified if either of isNaN x or -- isInfinite x is True. decodeFloat :: RealFloat a => a -> (Integer, Int) -- | encodeFloat performs the inverse of decodeFloat in the -- sense that for finite x with the exception of -0.0, -- uncurry encodeFloat (decodeFloat x) = x. -- encodeFloat m n is one of the two closest -- representable floating-point numbers to m*b^^n (or -- ±Infinity if overflow occurs); usually the closer, but if -- m contains too many bits, the result may be rounded in the -- wrong direction. encodeFloat :: RealFloat a => Integer -> Int -> a -- | exponent corresponds to the second component of -- decodeFloat. exponent 0 = 0 and for finite -- nonzero x, exponent x = snd (decodeFloat x) -- + floatDigits x. If x is a finite floating-point -- number, it is equal in value to significand x * b ^^ -- exponent x, where b is the floating-point radix. -- The behaviour is unspecified on infinite or NaN values. exponent :: RealFloat a => a -> Int -- | a constant function, returning the number of digits of -- floatRadix in the significand floatDigits :: RealFloat a => a -> Int -- | a constant function, returning the radix of the representation (often -- 2) floatRadix :: RealFloat a => a -> Integer -- | a constant function, returning the lowest and highest values the -- exponent may assume floatRange :: RealFloat a => a -> (Int, Int) -- | True if the argument is too small to be represented in -- normalized format isDenormalized :: RealFloat a => a -> Bool -- | True if the argument is an IEEE floating point number isIEEE :: RealFloat a => a -> Bool -- | True if the argument is an IEEE infinity or negative infinity isInfinite :: RealFloat a => a -> Bool -- | True if the argument is an IEEE "not-a-number" (NaN) value isNaN :: RealFloat a => a -> Bool -- | True if the argument is an IEEE negative zero isNegativeZero :: RealFloat a => a -> Bool -- | multiplies a floating-point number by an integer power of the radix scaleFloat :: RealFloat a => Int -> a -> a -- | The first component of decodeFloat, scaled to lie in the open -- interval (-1,1), either 0.0 or of absolute -- value >= 1/b, where b is the floating-point -- radix. The behaviour is unspecified on infinite or NaN -- values. significand :: RealFloat a => a -> a (*) :: Num a => a -> a -> a infixl 7 * (+) :: Num a => a -> a -> a infixl 6 + (-) :: Num a => a -> a -> a infixl 6 - -- | Absolute value. abs :: Num a => a -> a -- | Unary negation. negate :: Num a => a -> a -- | Sign of a number. The functions abs and signum should -- satisfy the law: -- --
--   abs x * signum x == x
--   
-- -- For real numbers, the signum is either -1 (negative), -- 0 (zero) or 1 (positive). signum :: Num a => a -> a -- | The method readList is provided to allow the programmer to give -- a specialised way of parsing lists of values. For example, this is -- used by the predefined Read instance of the Char type, -- where values of type String should be are expected to use -- double quotes, rather than square brackets. readList :: Read a => ReadS [a] -- | attempts to parse a value from the front of the string, returning a -- list of (parsed value, remaining string) pairs. If there is no -- successful parse, the returned list is empty. -- -- Derived instances of Read and Show satisfy the -- following: -- -- -- -- That is, readsPrec parses the string produced by -- showsPrec, and delivers the value that showsPrec started -- with. readsPrec :: Read a => Int -> ReadS a -- | Fractional division. (/) :: Fractional a => a -> a -> a infixl 7 / -- | Conversion from a Rational (that is Ratio -- Integer). A floating literal stands for an application of -- fromRational to a value of type Rational, so such -- literals have type (Fractional a) => a. fromRational :: Fractional a => Rational -> a -- | Reciprocal fraction. recip :: Fractional a => a -> a -- | integer division truncated toward negative infinity -- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. div :: Integral a => a -> a -> a infixl 7 `div` -- | simultaneous div and mod -- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. divMod :: Integral a => a -> a -> (a, a) -- | integer modulus, satisfying -- --
--   (x `div` y)*y + (x `mod` y) == x
--   
-- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. mod :: Integral a => a -> a -> a infixl 7 `mod` -- | integer division truncated toward zero -- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. quot :: Integral a => a -> a -> a infixl 7 `quot` -- | simultaneous quot and rem -- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. quotRem :: Integral a => a -> a -> (a, a) -- | integer remainder, satisfying -- --
--   (x `quot` y)*y + (x `rem` y) == x
--   
-- -- WARNING: This function is partial (because it throws when 0 is passed -- as the divisor) for all the integer types in base. rem :: Integral a => a -> a -> a infixl 7 `rem` -- | conversion to Integer toInteger :: Integral a => a -> Integer -- | the rational equivalent of its real argument with full precision toRational :: Real a => a -> Rational -- | ceiling x returns the least integer not less than -- x ceiling :: (RealFrac a, Integral b) => a -> b -- | floor x returns the greatest integer not greater than -- x floor :: (RealFrac a, Integral b) => a -> b -- | The function properFraction takes a real fractional number -- x and returns a pair (n,f) such that x = -- n+f, and: -- -- -- -- The default definitions of the ceiling, floor, -- truncate and round functions are in terms of -- properFraction. properFraction :: (RealFrac a, Integral b) => a -> (b, a) -- | round x returns the nearest integer to x; the -- even integer if x is equidistant between two integers round :: (RealFrac a, Integral b) => a -> b -- | truncate x returns the integer nearest x -- between zero and x truncate :: (RealFrac a, Integral b) => a -> b -- | A specialised variant of showsPrec, using precedence context -- zero, and returning an ordinary String. show :: Show a => a -> String -- | The method showList is provided to allow the programmer to give -- a specialised way of showing lists of values. For example, this is -- used by the predefined Show instance of the Char type, -- where values of type String should be shown in double quotes, -- rather than between square brackets. showList :: Show a => [a] -> ShowS -- | Convert a value to a readable String. -- -- showsPrec should satisfy the law -- --
--   showsPrec d x r ++ s  ==  showsPrec d x (r ++ s)
--   
-- -- Derived instances of Read and Show satisfy the -- following: -- -- -- -- That is, readsPrec parses the string produced by -- showsPrec, and delivers the value that showsPrec started -- with. showsPrec :: Show a => Int -> a -> ShowS (/=) :: Eq a => a -> a -> Bool infix 4 /= (==) :: Eq a => a -> a -> Bool infix 4 == (<) :: Ord a => a -> a -> Bool infix 4 < (<=) :: Ord a => a -> a -> Bool infix 4 <= (>) :: Ord a => a -> a -> Bool infix 4 > (>=) :: Ord a => a -> a -> Bool infix 4 >= compare :: Ord a => a -> a -> Ordering max :: Ord a => a -> a -> a min :: Ord a => a -> a -> a -- | A functor with application, providing operations to -- -- -- -- A minimal complete definition must include implementations of -- pure and of either <*> or liftA2. If it -- defines both, then they must behave the same as their default -- definitions: -- --
--   (<*>) = liftA2 id
--   
-- --
--   liftA2 f x y = f <$> x <*> y
--   
-- -- Further, any definition must satisfy the following: -- -- -- -- The other methods have the following default definitions, which may be -- overridden with equivalent specialized implementations: -- -- -- -- As a consequence of these laws, the Functor instance for -- f will satisfy -- -- -- -- It may be useful to note that supposing -- --
--   forall x y. p (q x y) = f x . g y
--   
-- -- it follows from the above that -- --
--   liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v
--   
-- -- If f is also a Monad, it should satisfy -- -- -- -- (which implies that pure and <*> satisfy the -- applicative functor laws). class Functor f => Applicative (f :: Type -> Type) -- | The Bounded class is used to name the upper and lower limits of -- a type. Ord is not a superclass of Bounded since types -- that are not totally ordered may also have upper and lower bounds. -- -- The Bounded class may be derived for any enumeration type; -- minBound is the first constructor listed in the data -- declaration and maxBound is the last. Bounded may also -- be derived for single-constructor datatypes whose constituent types -- are in Bounded. class () => Bounded a -- | Class Enum defines operations on sequentially ordered types. -- -- The enumFrom... methods are used in Haskell's translation of -- arithmetic sequences. -- -- Instances of Enum may be derived for any enumeration type -- (types whose constructors have no fields). The nullary constructors -- are assumed to be numbered left-to-right by fromEnum from -- 0 through n-1. See Chapter 10 of the Haskell -- Report for more details. -- -- For any type that is an instance of class Bounded as well as -- Enum, the following should hold: -- -- -- --
--   enumFrom     x   = enumFromTo     x maxBound
--   enumFromThen x y = enumFromThenTo x y bound
--     where
--       bound | fromEnum y >= fromEnum x = maxBound
--             | otherwise                = minBound
--   
class () => Enum a -- | The Eq class defines equality (==) and inequality -- (/=). All the basic datatypes exported by the Prelude -- are instances of Eq, and Eq may be derived for any -- datatype whose constituents are also instances of Eq. -- -- The Haskell Report defines no laws for Eq. However, instances -- are encouraged to follow these properties: -- -- -- -- Minimal complete definition: either == or /=. class () => Eq a -- | Trigonometric and hyperbolic functions and related functions. -- -- The Haskell Report defines no laws for Floating. However, -- (+), (*) and exp are -- customarily expected to define an exponential field and have the -- following properties: -- -- class Fractional a => Floating a -- | The Foldable class represents data structures that can be reduced to a -- summary value one element at a time. Strict left-associative folds are -- a good fit for space-efficient reduction, while lazy right-associative -- folds are a good fit for corecursive iteration, or for folds that -- short-circuit after processing an initial subsequence of the -- structure's elements. -- -- Instances can be derived automatically by enabling the -- DeriveFoldable extension. For example, a derived instance for -- a binary tree might be: -- --
--   {-# LANGUAGE DeriveFoldable #-}
--   data Tree a = Empty
--               | Leaf a
--               | Node (Tree a) a (Tree a)
--       deriving Foldable
--   
-- -- A more detailed description can be found in the Overview -- section of Data.Foldable#overview. -- -- For the class laws see the Laws section of -- Data.Foldable#laws. class () => Foldable (t :: Type -> Type) -- | Fractional numbers, supporting real division. -- -- The Haskell Report defines no laws for Fractional. However, -- (+) and (*) are customarily expected -- to define a division ring and have the following properties: -- -- -- -- Note that it isn't customarily expected that a type instance of -- Fractional implement a field. However, all instances in -- base do. class Num a => Fractional a -- | A type f is a Functor if it provides a function fmap -- which, given any types a and b lets you apply any -- function from (a -> b) to turn an f a into an -- f b, preserving the structure of f. Furthermore -- f needs to adhere to the following: -- -- -- -- Note, that the second law follows from the free theorem of the type -- fmap and the first law, so you need only check that the former -- condition holds. See -- https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or -- https://github.com/quchen/articles/blob/master/second_functor_law.md -- for an explanation. class () => Functor (f :: Type -> Type) -- | Integral numbers, supporting integer division. -- -- The Haskell Report defines no laws for Integral. However, -- Integral instances are customarily expected to define a -- Euclidean domain and have the following properties for the -- div/mod and quot/rem pairs, given suitable -- Euclidean functions f and g: -- -- -- -- An example of a suitable Euclidean function, for Integer's -- instance, is abs. -- -- In addition, toInteger should be total, and fromInteger -- should be a left inverse for it, i.e. fromInteger (toInteger i) = -- i. class (Real a, Enum a) => Integral a -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Instances of Monad should satisfy the following: -- -- -- -- Furthermore, the Monad and Applicative operations should -- relate as follows: -- -- -- -- The above laws imply: -- -- -- -- and that pure and (<*>) satisfy the applicative -- functor laws. -- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Applicative m => Monad (m :: Type -> Type) -- | When a value is bound in do-notation, the pattern on the left -- hand side of <- might not match. In this case, this class -- provides a function to recover. -- -- A Monad without a MonadFail instance may only be used in -- conjunction with pattern that always match, such as newtypes, tuples, -- data types with only a single data constructor, and irrefutable -- patterns (~pat). -- -- Instances of MonadFail should satisfy the following law: -- fail s should be a left zero for >>=, -- --
--   fail s >>= f  =  fail s
--   
-- -- If your Monad is also MonadPlus, a popular definition is -- --
--   fail _ = mzero
--   
-- -- fail s should be an action that runs in the monad itself, not -- an exception (except in instances of MonadIO). In particular, -- fail should not be implemented in terms of error. class Monad m => MonadFail (m :: Type -> Type) -- | The class of monoids (types with an associative binary operation that -- has an identity). Instances should satisfy the following: -- -- -- -- You can alternatively define mconcat instead of mempty, -- in which case the laws are: -- -- -- -- The method names refer to the monoid of lists under concatenation, but -- there are many other instances. -- -- Some types can be viewed as a monoid in more than one way, e.g. both -- addition and multiplication on numbers. In such cases we often define -- newtypes and make those instances of Monoid, e.g. -- Sum and Product. -- -- NOTE: Semigroup is a superclass of Monoid since -- base-4.11.0.0. class Semigroup a => Monoid a -- | Basic numeric class. -- -- The Haskell Report defines no laws for Num. However, -- (+) and (*) are customarily expected -- to define a ring and have the following properties: -- -- -- -- Note that it isn't customarily expected that a type instance of -- both Num and Ord implement an ordered ring. Indeed, in -- base only Integer and Rational do. class () => Num a -- | Conversion from an Integer. An integer literal represents the -- application of the function fromInteger to the appropriate -- value of type Integer, so such literals have type -- (Num a) => a. fromInteger :: Num a => Integer -> a -- | The Ord class is used for totally ordered datatypes. -- -- Instances of Ord can be derived for any user-defined datatype -- whose constituent types are in Ord. The declared order of the -- constructors in the data declaration determines the ordering in -- derived Ord instances. The Ordering datatype allows a -- single comparison to determine the precise ordering of two objects. -- -- Ord, as defined by the Haskell report, implements a total order -- and has the following properties: -- -- -- -- The following operator interactions are expected to hold: -- --
    --
  1. x >= y = y <= x
  2. --
  3. x < y = x <= y && x /= y
  4. --
  5. x > y = y < x
  6. --
  7. x < y = compare x y == LT
  8. --
  9. x > y = compare x y == GT
  10. --
  11. x == y = compare x y == EQ
  12. --
  13. min x y == if x <= y then x else y = True
  14. --
  15. max x y == if x >= y then x else y = True
  16. --
-- -- Note that (7.) and (8.) do not require min and -- max to return either of their arguments. The result is merely -- required to equal one of the arguments in terms of (==). -- -- Minimal complete definition: either compare or <=. -- Using compare can be more efficient for complex types. class Eq a => Ord a -- | Parsing of Strings, producing values. -- -- Derived instances of Read make the following assumptions, which -- derived instances of Show obey: -- -- -- -- For example, given the declarations -- --
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   
-- -- the derived instance of Read in Haskell 2010 is equivalent to -- --
--   instance (Read a) => Read (Tree a) where
--   
--           readsPrec d r =  readParen (d > app_prec)
--                            (\r -> [(Leaf m,t) |
--                                    ("Leaf",s) <- lex r,
--                                    (m,t) <- readsPrec (app_prec+1) s]) r
--   
--                         ++ readParen (d > up_prec)
--                            (\r -> [(u:^:v,w) |
--                                    (u,s) <- readsPrec (up_prec+1) r,
--                                    (":^:",t) <- lex s,
--                                    (v,w) <- readsPrec (up_prec+1) t]) r
--   
--             where app_prec = 10
--                   up_prec = 5
--   
-- -- Note that right-associativity of :^: is unused. -- -- The derived instance in GHC is equivalent to -- --
--   instance (Read a) => Read (Tree a) where
--   
--           readPrec = parens $ (prec app_prec $ do
--                                    Ident "Leaf" <- lexP
--                                    m <- step readPrec
--                                    return (Leaf m))
--   
--                        +++ (prec up_prec $ do
--                                    u <- step readPrec
--                                    Symbol ":^:" <- lexP
--                                    v <- step readPrec
--                                    return (u :^: v))
--   
--             where app_prec = 10
--                   up_prec = 5
--   
--           readListPrec = readListPrecDefault
--   
-- -- Why do both readsPrec and readPrec exist, and why does -- GHC opt to implement readPrec in derived Read instances -- instead of readsPrec? The reason is that readsPrec is -- based on the ReadS type, and although ReadS is mentioned -- in the Haskell 2010 Report, it is not a very efficient parser data -- structure. -- -- readPrec, on the other hand, is based on a much more efficient -- ReadPrec datatype (a.k.a "new-style parsers"), but its -- definition relies on the use of the RankNTypes language -- extension. Therefore, readPrec (and its cousin, -- readListPrec) are marked as GHC-only. Nevertheless, it is -- recommended to use readPrec instead of readsPrec -- whenever possible for the efficiency improvements it brings. -- -- As mentioned above, derived Read instances in GHC will -- implement readPrec instead of readsPrec. The default -- implementations of readsPrec (and its cousin, readList) -- will simply use readPrec under the hood. If you are writing a -- Read instance by hand, it is recommended to write it like so: -- --
--   instance Read T where
--     readPrec     = ...
--     readListPrec = readListPrecDefault
--   
class () => Read a -- | Real numbers. -- -- The Haskell report defines no laws for Real, however -- Real instances are customarily expected to adhere to the -- following law: -- -- class (Num a, Ord a) => Real a -- | Efficient, machine-independent access to the components of a -- floating-point number. class (RealFrac a, Floating a) => RealFloat a -- | Extracting components of fractions. class (Real a, Fractional a) => RealFrac a -- | The class of semigroups (types with an associative binary operation). -- -- Instances should satisfy the following: -- -- -- -- You can alternatively define sconcat instead of -- (<>), in which case the laws are: -- -- class () => Semigroup a -- | Conversion of values to readable Strings. -- -- Derived instances of Show have the following properties, which -- are compatible with derived instances of Read: -- -- -- -- For example, given the declarations -- --
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   
-- -- the derived instance of Show is equivalent to -- --
--   instance (Show a) => Show (Tree a) where
--   
--          showsPrec d (Leaf m) = showParen (d > app_prec) $
--               showString "Leaf " . showsPrec (app_prec+1) m
--            where app_prec = 10
--   
--          showsPrec d (u :^: v) = showParen (d > up_prec) $
--               showsPrec (up_prec+1) u .
--               showString " :^: "      .
--               showsPrec (up_prec+1) v
--            where up_prec = 5
--   
-- -- Note that right-associativity of :^: is ignored. For example, -- -- class () => Show a -- | Functors representing data structures that can be transformed to -- structures of the same shape by performing an -- Applicative (or, therefore, Monad) action on each -- element from left to right. -- -- A more detailed description of what same shape means, the -- various methods, how traversals are constructed, and example advanced -- use-cases can be found in the Overview section of -- Data.Traversable#overview. -- -- For the class laws see the Laws section of -- Data.Traversable#laws. class (Functor t, Foldable t) => Traversable (t :: Type -> Type) -- | A value of type IO a is a computation which, when -- performed, does some I/O before returning a value of type a. -- -- There is really only one way to "perform" an I/O action: bind it to -- Main.main in your program. When your program is run, the I/O -- will be performed. It isn't possible to perform I/O from an arbitrary -- function, unless that function is itself in the IO monad and -- called at some point, directly or indirectly, from Main.main. -- -- IO is a monad, so IO actions can be combined using -- either the do-notation or the >> and >>= -- operations from the Monad class. data () => IO a -- | The character type Char is an enumeration whose values -- represent Unicode (or equivalently ISO/IEC 10646) code points (i.e. -- characters, see http://www.unicode.org/ for details). This set -- extends the ISO 8859-1 (Latin-1) character set (the first 256 -- characters), which is itself an extension of the ASCII character set -- (the first 128 characters). A character literal in Haskell has type -- Char. -- -- To convert a Char to or from the corresponding Int value -- defined by Unicode, use toEnum and fromEnum from the -- Enum class respectively (or equivalently ord and -- chr). data () => Char -- | Double-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- double-precision type. data () => Double -- | Single-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- single-precision type. data () => Float -- | A fixed-precision integer type with at least the range [-2^29 .. -- 2^29-1]. The exact range for a given implementation can be -- determined by using minBound and maxBound from the -- Bounded class. data () => Int -- | Arbitrary precision integers. In contrast with fixed-size integral -- types such as Int, the Integer type represents the -- entire infinite range of integers. -- -- Integers are stored in a kind of sign-magnitude form, hence do not -- expect two's complement form when using bit operations. -- -- If the value is small (fit into an Int), IS constructor -- is used. Otherwise Integer and IN constructors are used -- to store a BigNat representing respectively the positive or the -- negative value magnitude. -- -- Invariant: Integer and IN are used iff value doesn't fit -- in IS data () => Integer -- | A Word is an unsigned integral type, with the same size as -- Int. data () => Word data () => Bool False :: Bool True :: Bool -- | The Either type represents values with two possibilities: a -- value of type Either a b is either Left -- a or Right b. -- -- The Either type is sometimes used to represent a value which is -- either correct or an error; by convention, the Left constructor -- is used to hold an error value and the Right constructor is -- used to hold a correct value (mnemonic: "right" also means "correct"). -- --

Examples

-- -- The type Either String Int is the type -- of values which can be either a String or an Int. The -- Left constructor can be used only on Strings, and the -- Right constructor can be used only on Ints: -- --
--   >>> let s = Left "foo" :: Either String Int
--   
--   >>> s
--   Left "foo"
--   
--   >>> let n = Right 3 :: Either String Int
--   
--   >>> n
--   Right 3
--   
--   >>> :type s
--   s :: Either String Int
--   
--   >>> :type n
--   n :: Either String Int
--   
-- -- The fmap from our Functor instance will ignore -- Left values, but will apply the supplied function to values -- contained in a Right: -- --
--   >>> let s = Left "foo" :: Either String Int
--   
--   >>> let n = Right 3 :: Either String Int
--   
--   >>> fmap (*2) s
--   Left "foo"
--   
--   >>> fmap (*2) n
--   Right 6
--   
-- -- The Monad instance for Either allows us to chain -- together multiple actions which may fail, and fail overall if any of -- the individual steps failed. First we'll write a function that can -- either parse an Int from a Char, or fail. -- --
--   >>> import Data.Char ( digitToInt, isDigit )
--   
--   >>> :{
--       let parseEither :: Char -> Either String Int
--           parseEither c
--             | isDigit c = Right (digitToInt c)
--             | otherwise = Left "parse error"
--   
--   >>> :}
--   
-- -- The following should work, since both '1' and '2' -- can be parsed as Ints. -- --
--   >>> :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x <- parseEither '1'
--             y <- parseEither '2'
--             return (x + y)
--   
--   >>> :}
--   
-- --
--   >>> parseMultiple
--   Right 3
--   
-- -- But the following should fail overall, since the first operation where -- we attempt to parse 'm' as an Int will fail: -- --
--   >>> :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x <- parseEither 'm'
--             y <- parseEither '2'
--             return (x + y)
--   
--   >>> :}
--   
-- --
--   >>> parseMultiple
--   Left "parse error"
--   
data () => Either a b Left :: a -> Either a b Right :: b -> Either a b -- | The Maybe type encapsulates an optional value. A value of type -- Maybe a either contains a value of type a -- (represented as Just a), or it is empty (represented -- as Nothing). Using Maybe is a good way to deal with -- errors or exceptional cases without resorting to drastic measures such -- as error. -- -- The Maybe type is also a monad. It is a simple kind of error -- monad, where all errors are represented by Nothing. A richer -- error monad can be built using the Either type. data () => Maybe a Nothing :: Maybe a Just :: a -> Maybe a data () => Ordering LT :: Ordering EQ :: Ordering GT :: Ordering -- | File and directory names are values of type String, whose -- precise meaning is operating system dependent. Files can be opened, -- yielding a handle which can then be used to operate on the contents of -- that file. type FilePath = String -- | The Haskell 2010 type for exceptions in the IO monad. Any I/O -- operation may raise an IOException instead of returning a -- result. For a more general type of exception, including also those -- that arise in pure code, see Exception. -- -- In Haskell 2010, this is an opaque type. type IOError = IOException -- | Arbitrary-precision rational numbers, represented as a ratio of two -- Integer values. A rational number may be constructed using the -- % operator. type Rational = Ratio Integer -- | A parser for a type a, represented as a function that takes a -- String and returns a list of possible parses as -- (a,String) pairs. -- -- Note that this kind of backtracking parser is very inefficient; -- reading a large structure may be quite slow (cf ReadP). type ReadS a = String -> [(a, String)] -- | The shows functions return a function that prepends the -- output String to an existing String. This allows -- constant-time concatenation of results using function composition. type ShowS = String -> String -- | A String is a list of characters. String constants in Haskell -- are values of type String. -- -- See Data.List for operations on lists. type String = [Char] -- | Lifted, homogeneous equality. By lifted, we mean that it can be bogus -- (deferred type error). By homogeneous, the two types a and -- b must have the same kinds. class a ~# b => (a :: k) ~ (b :: k) infix 4 ~ module Data.List.Compat -- | Use compareLength xs n as a safer and faster -- alternative to compare (length xs) n. -- Similarly, it's better to write compareLength xs 10 == LT -- instead of length xs < 10. -- -- While length would force and traverse the entire spine of -- xs (which could even diverge if xs is infinite), -- compareLength traverses at most n elements to -- determine its result. -- --
--   >>> compareLength [] 0
--   EQ
--   
--   >>> compareLength [] 1
--   LT
--   
--   >>> compareLength ['a'] 1
--   EQ
--   
--   >>> compareLength ['a', 'b'] 1
--   GT
--   
--   >>> compareLength [0..] 100
--   GT
--   
--   >>> compareLength undefined (-1)
--   GT
--   
--   >>> compareLength ('a' : undefined) 0
--   GT
--   
compareLength :: [a] -> Int -> Ordering -- | The inits1 function returns all non-empty initial segments of -- the argument, shortest first. -- --

Laziness

-- -- Note that inits1 has the following strictness property: -- inits1 (xs ++ _|_) = inits1 xs ++ _|_ -- -- In particular, inits1 _|_ = _|_ -- --

Examples

-- --
--   >>> inits1 "abc"
--   ['a' :| "",'a' :| "b",'a' :| "bc"]
--   
-- --
--   >>> inits1 []
--   []
--   
-- -- inits1 is productive on infinite lists: -- --
--   >>> take 3 $ inits1 [1..]
--   [1 :| [],1 :| [2],1 :| [2,3]]
--   
inits1 :: [a] -> [NonEmpty a] -- | <math>. The tails1 function returns all non-empty final -- segments of the argument, longest first. -- --

Laziness

-- -- Note that tails1 has the following strictness property: -- tails1 _|_ = _|_ -- --
--   >>> tails1 undefined
--   *** Exception: Prelude.undefined
--   
-- --
--   >>> drop 1 (tails1 [undefined, 1, 2])
--   [1 :| [2],2 :| []]
--   
-- --

Examples

-- --
--   >>> tails1 "abc"
--   ['a' :| "bc",'b' :| "c",'c' :| ""]
--   
-- --
--   >>> tails1 [1, 2, 3]
--   [1 :| [2,3],2 :| [3],3 :| []]
--   
-- --
--   >>> tails1 []
--   []
--   
tails1 :: [a] -> [NonEmpty a] -- | The builtin list type, usually written in its non-prefix form -- [a]. -- --

Examples

-- -- Unless the OverloadedLists extension is enabled, list literals are -- syntactic sugar for repeated applications of : and -- []. -- --
--   >>> 1:2:3:4:[] == [1,2,3,4]
--   True
--   
-- -- Similarly, unless the OverloadedStrings extension is enabled, string -- literals are syntactic sugar for a lists of characters. -- --
--   >>> ['h','e','l','l','o'] == "hello"
--   True
--   
data () => [] a -- | List index (subscript) operator, starting from 0. Returns -- Nothing if the index is out of bounds -- --
--   >>> ['a', 'b', 'c'] !? 0
--   Just 'a'
--   
--   >>> ['a', 'b', 'c'] !? 2
--   Just 'c'
--   
--   >>> ['a', 'b', 'c'] !? 3
--   Nothing
--   
--   >>> ['a', 'b', 'c'] !? (-1)
--   Nothing
--   
-- -- This is the total variant of the partial !! operator. -- -- WARNING: This function takes linear time in the index. (!?) :: [a] -> Int -> Maybe a infixl 9 !? -- | <math>. Decompose a list into init and last. -- -- -- -- Since: 4.19.0.0 -- --
--   >>> unsnoc []
--   Nothing
--   
--   >>> unsnoc [1]
--   Just ([],1)
--   
--   >>> unsnoc [1, 2, 3]
--   Just ([1,2],3)
--   
-- -- Laziness: -- --
--   >>> fst <$> unsnoc [undefined]
--   Just []
--   
--   >>> head . fst <$> unsnoc (1 : undefined)
--   Just *** Exception: Prelude.undefined
--   
--   >>> head . fst <$> unsnoc (1 : 2 : undefined)
--   Just 1
--   
-- -- unsnoc is dual to uncons: for a finite list xs -- --
--   unsnoc xs = (\(hd, tl) -> (reverse tl, hd)) <$> uncons (reverse xs)
--   
unsnoc :: [a] -> Maybe ([a], a) -- | This backports the modern Data.Semigroup interface back to -- base-4.9/GHC 8.0. module Data.List.NonEmpty.Compat -- | Non-empty (and non-strict) list type. data () => NonEmpty a (:|) :: a -> [a] -> NonEmpty a infixr 5 :| -- | 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 -- | transpose for NonEmpty, behaves the same as -- transpose The rows/columns need not be the same length, in -- which case > transpose . transpose /= id transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a) -- | sortBy for NonEmpty, behaves the same as sortBy sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a -- | sortWith for NonEmpty, behaves the same as: -- --
--   sortBy . comparing
--   
sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a -- | Number of elements in NonEmpty list. length :: NonEmpty a -> Int -- | Use compareLength xs n as a safer and faster -- alternative to compare (length xs) n. -- Similarly, it's better to write compareLength xs 10 == LT -- instead of length xs < 10. -- -- While length would force and traverse the entire spine of -- xs (which could even diverge if xs is infinite), -- compareLength traverses at most n elements to -- determine its result. -- --
--   >>> compareLength ('a' :| []) 1
--   EQ
--   
--   >>> compareLength ('a' :| ['b']) 3
--   LT
--   
--   >>> compareLength (0 :| [1..]) 100
--   GT
--   
--   >>> compareLength undefined 0
--   GT
--   
--   >>> compareLength ('a' :| 'b' : undefined) 1
--   GT
--   
compareLength :: NonEmpty a -> Int -> Ordering -- | 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] -- | Construct a NonEmpty list from a single element. singleton :: a -> NonEmpty a -- | Prepend an element to the stream. (<|) :: a -> NonEmpty a -> NonEmpty a infixr 5 <| -- | 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)) -- | The unfoldr function is analogous to Data.List's -- unfoldr operation. unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b -- | Sort a stream. sort :: Ord a => NonEmpty a -> NonEmpty a -- | Sort a NonEmpty on a user-supplied projection of its elements. -- See sortOn for more detailed information. -- --

Examples

-- --
--   >>> sortOn fst $ (2, "world") :| [(4, "!"), (1, "Hello")]
--   (1,"Hello") :| [(2,"world"),(4,"!")]
--   
-- --
--   >>> sortOn length $ "jim" :| ["creed", "pam", "michael", "dwight", "kevin"]
--   "jim" :| ["pam","creed","kevin","dwight","michael"]
--   
-- --

Performance notes

-- -- This function minimises the projections performed, by materialising -- the projections in an intermediate list. -- -- For trivial projections, you should prefer using sortBy with -- comparing, for example: -- --
--   >>> sortBy (comparing fst) $ (3, 1) :| [(2, 2), (1, 3)]
--   (1,3) :| [(2,2),(3,1)]
--   
-- -- Or, for the exact same API as sortOn, you can use `sortBy . -- comparing`: -- --
--   >>> (sortBy . comparing) fst $ (3, 1) :| [(2, 2), (1, 3)]
--   (1,3) :| [(2,2),(3,1)]
--   
-- -- sortWith is an alias for `sortBy . comparing`. -- -- Since: 4.20.0.0 sortOn :: Ord b => (a -> b) -> 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, starting with the shortest. The -- result is NonEmpty because the result always contains the empty -- list as the first element. -- --
--   inits [1,2,3] == [] :| [[1], [1,2], [1,2,3]]
--   inits [1] == [] :| [[1]]
--   inits [] == [] :| []
--   
inits :: Foldable f => f a -> NonEmpty [a] -- | The inits1 function takes a NonEmpty stream xs -- and returns all the NonEmpty finite prefixes of xs, -- starting with the shortest. -- --
--   inits1 (1 :| [2,3]) == (1 :| []) :| [1 :| [2], 1 :| [2,3]]
--   inits1 (1 :| []) == (1 :| []) :| []
--   
inits1 :: NonEmpty a -> NonEmpty (NonEmpty a) -- | The tails function takes a stream xs and returns all -- the suffixes of xs, starting with the longest. The result is -- NonEmpty because the result always contains the empty list as -- the last element. -- --
--   tails [1,2,3] == [1,2,3] :| [[2,3], [3], []]
--   tails [1] == [1] :| [[]]
--   tails [] == [] :| []
--   
tails :: Foldable f => f a -> NonEmpty [a] -- | The tails1 function takes a NonEmpty stream xs -- and returns all the non-empty suffixes of xs, starting with -- the longest. -- --
--   tails1 (1 :| [2,3]) == (1 :| [2,3]) :| [2 :| [3], 3 :| []]
--   tails1 (1 :| []) == (1 :| []) :| []
--   
tails1 :: NonEmpty a -> NonEmpty (NonEmpty a) -- | A monomorphic version of <> for NonEmpty. -- --
--   >>> append (1 :| []) (2 :| [3])
--   1 :| [2,3]
--   
append :: NonEmpty a -> NonEmpty a -> NonEmpty a -- | Attach a list at the end of a NonEmpty. -- --
--   >>> appendList (1 :| [2,3]) []
--   1 :| [2,3]
--   
-- --
--   >>> appendList (1 :| [2,3]) [4,5]
--   1 :| [2,3,4,5]
--   
appendList :: NonEmpty a -> [a] -> NonEmpty a -- | Attach a list at the beginning of a NonEmpty. -- --
--   >>> prependList [] (1 :| [2,3])
--   1 :| [2,3]
--   
-- --
--   >>> prependList [negate 1, 0] (1 :| [2, 3])
--   -1 :| [0,1,2,3]
--   
prependList :: [a] -> NonEmpty 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 -- | some1 x sequences x one or more times. some1 :: Alternative f => f a -> f (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] -- | groupWith operates like group, but uses the provided -- projection when comparing for equality groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a] -- | groupAllWith operates like groupWith, but sorts the list -- first so that each equivalence class has, at most, one list in the -- output groupAllWith :: Ord b => (a -> b) -> [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) -- | groupWith1 is to group1 as groupWith is to -- group groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | groupAllWith1 is to groupWith1 as groupAllWith is -- to groupWith groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) -- | The permutations function returns the list of all permutations -- of the argument. -- -- Since: 4.20.0.0 permutations :: [a] -> NonEmpty [a] -- | permutations1 operates like permutations, but uses the -- knowledge that its input is non-empty to produce output where every -- element is non-empty. -- --
--   permutations1 = fmap fromList . permutations . toList
--   
-- -- Since: 4.20.0.0 permutations1 :: NonEmpty a -> NonEmpty (NonEmpty a) -- | The isPrefixOf function returns True if the first -- argument is a prefix of the second. isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool -- | The nub function removes duplicate elements from a list. In -- particular, it keeps only the first occurrence of each element. (The -- name nub means 'essence'.) It is a special case of -- nubBy, which allows the programmer to supply their own -- inequality test. nub :: Eq a => NonEmpty a -> NonEmpty a -- | The nubBy function behaves just like nub, except it uses -- a user-supplied equality predicate instead of the overloaded == -- function. nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -- | 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. (!!) :: HasCallStack => NonEmpty a -> Int -> a infixl 9 !! -- | 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) -- | Converts a normal list to a NonEmpty stream. -- -- Raises an error if given an empty list. fromList :: HasCallStack => [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) -- | Compute n-ary logic exclusive OR operation on NonEmpty list. xor :: NonEmpty Bool -> Bool -- | Reexports Data.List.NonEmpty.Compat from a globally unique -- namespace. module Data.List.NonEmpty.Compat.Repl -- | Reexports Data.List.Compat from a globally unique namespace. module Data.List.Compat.Repl module Data.Bitraversable.Compat -- | Traverses only over the first argument. -- --
--   firstA f ≡ bitraverse f pure
--   
firstA :: Bitraversable t => Applicative f => (a -> f c) -> t a b -> f (t c b) -- | Traverses only over the second argument. -- --
--   secondA f ≡ bitraverse pure f
--   
-- --

Examples

-- -- Basic usage: -- --
--   >>> secondA (find odd) (Left [])
--   Just (Left [])
--   
-- --
--   >>> secondA (find odd) (Left [1, 2, 3])
--   Just (Left [1,2,3])
--   
-- --
--   >>> secondA (find odd) (Right [4, 5])
--   Just (Right 5)
--   
-- --
--   >>> secondA (find odd) ([1, 2, 3], [4, 5])
--   Just ([1,2,3],5)
--   
-- --
--   >>> secondA (find odd) ([1,2,3], [4])
--   Nothing
--   
secondA :: Bitraversable t => Applicative f => (b -> f c) -> t a b -> f (t a c) -- | Reexports Data.Bitraversable.Compat from a globally unique -- namespace. module Data.Bitraversable.Compat.Repl -- | Reexports Prelude.Compat from a globally unique namespace. module Prelude.Compat.Repl -- | Miscellaneous information about the system environment. module System.Environment.Compat -- | Computation getArgs returns a list of the program's command -- line arguments (not including the program name). getArgs :: IO [String] -- | Computation getProgName returns the name of the program as it -- was invoked. -- -- However, this is hard-to-impossible to implement on some non-Unix -- OSes, so instead, for maximum portability, we just return the leafname -- of the program as invoked. Even then there are some differences -- between platforms: on Windows, for example, a program invoked as foo -- is probably really FOO.EXE, and that is what -- getProgName will return. getProgName :: IO String -- | Computation getEnv var returns the value of the -- environment variable var. For the inverse, the setEnv -- function can be used. -- -- This computation may fail with: -- -- getEnv :: String -> IO String -- | Return the value of the environment variable var, or -- Nothing if there is no such value. -- -- For POSIX users, this is equivalent to getEnv. lookupEnv :: String -> IO (Maybe String) -- | setEnv name value sets the specified environment variable to -- value. -- -- Early versions of this function operated under the mistaken belief -- that setting an environment variable to the empty string on -- Windows removes that environment variable from the environment. For -- the sake of compatibility, it adopted that behavior on POSIX. In -- particular -- --
--   setEnv name ""
--   
-- -- has the same effect as -- --
--   unsetEnv name
--   
-- -- If you'd like to be able to set environment variables to blank -- strings, use setEnv. -- -- Throws IOException if name is the empty string or -- contains an equals sign. setEnv :: String -> String -> IO () -- | unsetEnv name removes the specified environment variable from -- the environment of the current process. -- -- Throws IOException if name is the empty string or -- contains an equals sign. unsetEnv :: String -> IO () -- | withArgs args act - while executing action -- act, have getArgs return args. withArgs :: [String] -> IO a -> IO a -- | withProgName name act - while executing action -- act, have getProgName return name. withProgName :: String -> IO a -> IO a -- | getEnvironment retrieves the entire environment as a list of -- (key,value) pairs. -- -- If an environment entry does not contain an '=' character, -- the key is the whole entry and the value is the -- empty string. getEnvironment :: IO [(String, String)] -- | Reexports System.Environment.Compat from a globally unique -- namespace. module System.Environment.Compat.Repl module System.Exit.Compat -- | Write given error message to stderr and terminate with -- exitFailure. die :: String -> IO a -- | Reexports System.Exit.Compat from a globally unique namespace. module System.Exit.Compat.Repl module System.IO.Compat -- | The getContents' operation returns all user input as a single -- string, which is fully read before being returned (same as -- hGetContents' stdin). getContents' :: IO String -- | The hGetContents' operation reads all input on the given handle -- before returning it as a String and closing the handle. hGetContents' :: Handle -> IO String -- | The readFile' function reads a file and returns the contents of -- the file as a string. The file is fully read before being returned, as -- with getContents'. readFile' :: FilePath -> IO String -- | Reexports System.IO.Compat from a globally unique namespace. module System.IO.Compat.Repl module System.IO.Error.Compat -- | An error indicating that the operation failed because the resource -- vanished. See resourceVanishedErrorType. isResourceVanishedError :: IOError -> Bool -- | I/O error where the operation failed because the resource vanished. -- This happens when, for example, attempting to write to a closed socket -- or attempting to write to a named pipe that was deleted. resourceVanishedErrorType :: IOErrorType -- | I/O error where the operation failed because the resource vanished. -- See resourceVanishedErrorType. isResourceVanishedErrorType :: IOErrorType -> Bool -- | Reexports System.IO.Error.Compat from a globally unique -- namespace. module System.IO.Error.Compat.Repl module System.IO.Unsafe.Compat -- | A slightly faster version of fixIO that may not be safe to use -- with multiple threads. The unsafety arises when used like this: -- --
--   unsafeFixIO $ \r -> do
--      forkIO (print r)
--      return (...)
--   
-- -- In this case, the child thread will receive a NonTermination -- exception instead of waiting for the value of r to be -- computed. unsafeFixIO :: (a -> IO a) -> IO a -- | This version of unsafePerformIO is more efficient because it -- omits the check that the IO is only being performed by a single -- thread. Hence, when you use unsafeDupablePerformIO, there is a -- possibility that the IO action may be performed multiple times (on a -- multiprocessor), and you should therefore ensure that it gives the -- same results each time. It may even happen that one of the duplicated -- IO actions is only run partially, and then interrupted in the middle -- without an exception being raised. Therefore, functions like -- bracket cannot be used safely within -- unsafeDupablePerformIO. unsafeDupablePerformIO :: IO a -> a -- | Reexports System.IO.Unsafe.Compat from a globally unique -- namespace. module System.IO.Unsafe.Compat.Repl module Text.Read.Compat -- | Parsing of Strings, producing values. -- -- Derived instances of Read make the following assumptions, which -- derived instances of Show obey: -- -- -- -- For example, given the declarations -- --
--   infixr 5 :^:
--   data Tree a =  Leaf a  |  Tree a :^: Tree a
--   
-- -- the derived instance of Read in Haskell 2010 is equivalent to -- --
--   instance (Read a) => Read (Tree a) where
--   
--           readsPrec d r =  readParen (d > app_prec)
--                            (\r -> [(Leaf m,t) |
--                                    ("Leaf",s) <- lex r,
--                                    (m,t) <- readsPrec (app_prec+1) s]) r
--   
--                         ++ readParen (d > up_prec)
--                            (\r -> [(u:^:v,w) |
--                                    (u,s) <- readsPrec (up_prec+1) r,
--                                    (":^:",t) <- lex s,
--                                    (v,w) <- readsPrec (up_prec+1) t]) r
--   
--             where app_prec = 10
--                   up_prec = 5
--   
-- -- Note that right-associativity of :^: is unused. -- -- The derived instance in GHC is equivalent to -- --
--   instance (Read a) => Read (Tree a) where
--   
--           readPrec = parens $ (prec app_prec $ do
--                                    Ident "Leaf" <- lexP
--                                    m <- step readPrec
--                                    return (Leaf m))
--   
--                        +++ (prec up_prec $ do
--                                    u <- step readPrec
--                                    Symbol ":^:" <- lexP
--                                    v <- step readPrec
--                                    return (u :^: v))
--   
--             where app_prec = 10
--                   up_prec = 5
--   
--           readListPrec = readListPrecDefault
--   
-- -- Why do both readsPrec and readPrec exist, and why does -- GHC opt to implement readPrec in derived Read instances -- instead of readsPrec? The reason is that readsPrec is -- based on the ReadS type, and although ReadS is mentioned -- in the Haskell 2010 Report, it is not a very efficient parser data -- structure. -- -- readPrec, on the other hand, is based on a much more efficient -- ReadPrec datatype (a.k.a "new-style parsers"), but its -- definition relies on the use of the RankNTypes language -- extension. Therefore, readPrec (and its cousin, -- readListPrec) are marked as GHC-only. Nevertheless, it is -- recommended to use readPrec instead of readsPrec -- whenever possible for the efficiency improvements it brings. -- -- As mentioned above, derived Read instances in GHC will -- implement readPrec instead of readsPrec. The default -- implementations of readsPrec (and its cousin, readList) -- will simply use readPrec under the hood. If you are writing a -- Read instance by hand, it is recommended to write it like so: -- --
--   instance Read T where
--     readPrec     = ...
--     readListPrec = readListPrecDefault
--   
class () => Read a -- | attempts to parse a value from the front of the string, returning a -- list of (parsed value, remaining string) pairs. If there is no -- successful parse, the returned list is empty. -- -- Derived instances of Read and Show satisfy the -- following: -- -- -- -- That is, readsPrec parses the string produced by -- showsPrec, and delivers the value that showsPrec started -- with. readsPrec :: Read a => Int -> ReadS a -- | The method readList is provided to allow the programmer to give -- a specialised way of parsing lists of values. For example, this is -- used by the predefined Read instance of the Char type, -- where values of type String should be are expected to use -- double quotes, rather than square brackets. readList :: Read a => ReadS [a] -- | Proposed replacement for readsPrec using new-style parsers (GHC -- only). readPrec :: Read a => ReadPrec a -- | Proposed replacement for readList using new-style parsers (GHC -- only). The default definition uses readList. Instances that -- define readPrec should also define readListPrec as -- readListPrecDefault. readListPrec :: Read a => ReadPrec [a] -- | A parser for a type a, represented as a function that takes a -- String and returns a list of possible parses as -- (a,String) pairs. -- -- Note that this kind of backtracking parser is very inefficient; -- reading a large structure may be quite slow (cf ReadP). type ReadS a = String -> [(a, String)] -- | equivalent to readsPrec with a precedence of 0. reads :: Read a => ReadS a -- | The read function reads input from a string, which must be -- completely consumed by the input process. read fails with an -- error if the parse is unsuccessful, and it is therefore -- discouraged from being used in real applications. Use readMaybe -- or readEither for safe alternatives. -- --
--   >>> read "123" :: Int
--   123
--   
-- --
--   >>> read "hello" :: Int
--   *** Exception: Prelude.read: no parse
--   
read :: Read a => String -> a -- | readParen True p parses what p parses, -- but surrounded with parentheses. -- -- readParen False p parses what p -- parses, but optionally surrounded with parentheses. readParen :: Bool -> ReadS a -> ReadS a -- | The lex function reads a single lexeme from the input, -- discarding initial white space, and returning the characters that -- constitute the lexeme. If the input string contains only white space, -- lex returns a single successful `lexeme' consisting of the -- empty string. (Thus lex "" = [("","")].) If there is -- no legal lexeme at the beginning of the input string, lex fails -- (i.e. returns []). -- -- This lexer is not completely faithful to the Haskell lexical syntax in -- the following respects: -- -- lex :: ReadS String data () => Lexeme -- | Character literal Char :: Char -> Lexeme -- | String literal, with escapes interpreted String :: String -> Lexeme -- | Punctuation or reserved symbol, e.g. (, :: Punc :: String -> Lexeme -- | Haskell identifier, e.g. foo, Baz Ident :: String -> Lexeme -- | Haskell symbol, e.g. >>, :% Symbol :: String -> Lexeme Number :: Number -> Lexeme EOF :: Lexeme -- | Parse a single lexeme lexP :: ReadPrec Lexeme -- | (parens p) parses "P", "(P0)", "((P0))", etc, where -- p parses "P" in the current precedence context and parses -- "P0" in precedence context zero parens :: ReadPrec a -> ReadPrec a -- | A possible replacement definition for the readList method (GHC -- only). This is only needed for GHC, and even then only for Read -- instances where readListPrec isn't defined as -- readListPrecDefault. readListDefault :: Read a => ReadS [a] -- | A possible replacement definition for the readListPrec method, -- defined using readPrec (GHC only). readListPrecDefault :: Read a => ReadPrec [a] -- | Parse a string using the Read instance. Succeeds if there is -- exactly one valid result. A Left value indicates a parse error. -- --
--   >>> readEither "123" :: Either String Int
--   Right 123
--   
-- --
--   >>> readEither "hello" :: Either String Int
--   Left "Prelude.read: no parse"
--   
readEither :: Read a => String -> Either String a -- | Parse a string using the Read instance. Succeeds if there is -- exactly one valid result. -- --
--   >>> readMaybe "123" :: Maybe Int
--   Just 123
--   
-- --
--   >>> readMaybe "hello" :: Maybe Int
--   Nothing
--   
readMaybe :: Read a => String -> Maybe a -- | Reexports Text.Read.Compat from a globally unique namespace. module Text.Read.Compat.Repl module Text.Read.Lex.Compat readBinP :: (Eq a, Num a) => ReadP a -- | Reexports Text.Read.Lex.Compat from a globally unique -- namespace. module Text.Read.Lex.Compat.Repl module Type.Reflection.Compat -- | Use a TypeRep as Typeable evidence. -- -- The TypeRep pattern synonym brings a Typeable constraint -- into scope and can be used in place of withTypeable. -- --
--   f :: TypeRep a -> ..
--   f rep = withTypeable {- Typeable a in scope -}
--   
--   f :: TypeRep a -> ..
--   f TypeRep = {- Typeable a in scope -}
--   
withTypeable :: forall k (a :: k) (rep :: RuntimeRep) (r :: TYPE rep). TypeRep a -> (Typeable a => r) -> r -- | A explicitly bidirectional pattern synonym to construct a concrete -- representation of a type. -- -- As an expression: Constructs a singleton TypeRep a -- given a implicit 'Typeable a' constraint: -- --
--   TypeRep @a :: Typeable a => TypeRep a
--   
-- -- As a pattern: Matches on an explicit TypeRep a witness -- bringing an implicit Typeable a constraint into scope. -- --
--   f :: TypeRep a -> ..
--   f TypeRep = {- Typeable a in scope -}
--   
pattern TypeRep :: () => Typeable a => TypeRep a -- | Type equality decision -- -- Since: 4.19.0.0 decTypeRep :: forall k1 k2 (a :: k1) (b :: k2). TypeRep a -> TypeRep b -> Either ((a :~~: b) -> Void) (a :~~: b) module Data.Typeable.Compat -- | Extract a witness of heterogeneous equality of two types heqT :: forall {k1} {k2} (a :: k1) (b :: k2). (Typeable a, Typeable b) => Maybe (a :~~: b) -- | Decide an equality of two types -- -- Since: 4.19.0.0 decT :: forall a b. (Typeable a, Typeable b) => Either ((a :~: b) -> Void) (a :~: b) -- | Decide heterogeneous equality of two types. -- -- Since: 4.19.0.0 hdecT :: forall a b. (Typeable a, Typeable b) => Either ((a :~~: b) -> Void) (a :~~: b) -- | Reexports Data.Typeable.Compat from a globally unique -- namespace. module Data.Typeable.Compat.Repl -- | Reexports Type.Reflection.Compat from a globally unique -- namespace. module Type.Reflection.Compat.Repl