Safe Haskell  SafeInferred 

Language  GHC2021 
A prelude composed by overlaying numhask on Prelude, together with a few minor tweaks needed for RebindableSyntax.
Synopsis
 module NumHask.Algebra.Additive
 module NumHask.Algebra.Field
 module NumHask.Algebra.Group
 module NumHask.Algebra.Lattice
 module NumHask.Algebra.Action
 module NumHask.Algebra.Multiplicative
 module NumHask.Algebra.Ring
 module NumHask.Algebra.Metric
 module NumHask.Data.Complex
 module NumHask.Data.Integral
 module NumHask.Data.Rational
 module NumHask.Exception
 ifThenElse :: Bool > a > a > a
 fromList :: IsList l => [Item l] > l
 fromListN :: IsList l => Int > [Item l] > l
 data Natural where
 module GHC.OverloadedLabels
 module Data.Bool
 module Data.Kind
 module GHC.Generics
 module Control.Applicative
 module Data.Traversable
 newtype Any = Any {}
 class Semigroup a where
 newtype Last a = Last {
 getLast :: a
 newtype First a = First {
 getFirst :: a
 newtype All = All {}
 newtype Endo a = Endo {
 appEndo :: a > a
 newtype Dual a = Dual {
 getDual :: a
 newtype WrappedMonoid m = WrapMonoid {
 unwrapMonoid :: m
 type ArgMax a b = Max (Arg a b)
 type ArgMin a b = Min (Arg a b)
 data Arg a b = Arg a b
 stimesIdempotent :: Integral b => b > a > a
 stimesIdempotentMonoid :: (Integral b, Monoid a) => b > a > a
 stimesMonoid :: (Integral b, Monoid a) => b > a > a
 cycle1 :: Semigroup m => m > m
 diff :: Semigroup m => m > Endo m
 mtimesDefault :: (Integral b, Monoid a) => b > a > a
 module Data.Maybe
 ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b
 const :: a > b > a
 flip :: (a > b > c) > b > a > c
 fix :: (a > a) > a
 on :: (b > b > c) > (a > b) > a > a > c
 (&) :: a > (a > b) > b
 applyWhen :: Bool > (a > a) > a > a
 module Control.Category
 class Foldable (t :: Type > Type) where
 fold :: Monoid m => t m > m
 foldMap :: Monoid m => (a > m) > t a > m
 foldMap' :: Monoid m => (a > m) > t a > m
 foldr :: (a > b > b) > b > t a > b
 foldr' :: (a > b > b) > b > t a > b
 foldl :: (b > a > b) > b > t a > b
 foldl' :: (b > a > b) > b > t a > b
 foldr1 :: (a > a > a) > t a > a
 foldl1 :: (a > a > a) > t a > a
 toList :: t a > [a]
 null :: t a > Bool
 length :: t a > Int
 elem :: Eq a => a > t a > Bool
 maximum :: Ord a => t a > a
 minimum :: Ord a => t a > a
 maximumBy :: Foldable t => (a > a > Ordering) > t a > a
 minimumBy :: Foldable t => (a > a > Ordering) > t a > a
 concat :: Foldable t => t [a] > [a]
 and :: Foldable t => t Bool > Bool
 or :: Foldable t => t Bool > Bool
 any :: Foldable t => (a > Bool) > t a > Bool
 all :: Foldable t => (a > Bool) > t a > Bool
 notElem :: (Foldable t, Eq a) => a > t a > Bool
 concatMap :: Foldable t => (a > [b]) > t a > [b]
 foldrM :: (Foldable t, Monad m) => (a > b > m b) > b > t a > m b
 foldlM :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m b
 traverse_ :: (Foldable t, Applicative f) => (a > f b) > t a > f ()
 for_ :: (Foldable t, Applicative f) => t a > (a > f b) > f ()
 mapM_ :: (Foldable t, Monad m) => (a > m b) > t a > m ()
 forM_ :: (Foldable t, Monad m) => t a > (a > m b) > m ()
 sequenceA_ :: (Foldable t, Applicative f) => t (f a) > f ()
 sequence_ :: (Foldable t, Monad m) => t (m a) > m ()
 asum :: (Foldable t, Alternative f) => t (f a) > f a
 msum :: (Foldable t, MonadPlus m) => t (m a) > m a
 find :: Foldable t => (a > Bool) > t a > Maybe a
 data Int
 data Integer
 data Double
 data Float
 class Show a where
 class Bounded a where
 class Enum a where
 succ :: a > a
 pred :: a > a
 toEnum :: Int > a
 fromEnum :: a > Int
 enumFrom :: a > [a]
 enumFromThen :: a > a > [a]
 enumFromTo :: a > a > [a]
 enumFromThenTo :: a > a > a > [a]
 class (Real a, Fractional a) => RealFrac a
 class Read a where
 data IO a
 class Eq a => Ord a where
 type String = [Char]
 data Char
 data Word
 data Maybe a
 class a ~# b => (a :: k) ~ (b :: k)
 class Num a => Fractional a
 class (Num a, Ord a) => Real a
 class Eq a where
 class Semigroup a => Monoid a where
 class Semigroup a where
 (<>) :: a > a > a
 class Functor f => Applicative (f :: Type > Type) where
 class Functor (f :: Type > Type) where
 class Applicative m => Monad (m :: Type > Type) where
 data Either a b
 type IOError = IOException
 class Fractional a => Floating a
 class Num a
 class (RealFrac a, Floating a) => RealFloat a where
 floatRadix :: a > Integer
 floatDigits :: a > Int
 floatRange :: a > (Int, Int)
 decodeFloat :: a > (Integer, Int)
 encodeFloat :: Integer > Int > a
 exponent :: a > Int
 significand :: a > a
 scaleFloat :: Int > a > a
 isNaN :: a > Bool
 isInfinite :: a > Bool
 isDenormalized :: a > Bool
 isNegativeZero :: a > Bool
 isIEEE :: a > Bool
 class Monad m => MonadFail (m :: Type > Type) where
 class Foldable (t :: Type > Type) where
 foldMap :: Monoid m => (a > m) > t a > m
 foldr :: (a > b > b) > b > t a > b
 foldl :: (b > a > b) > b > t a > b
 foldr1 :: (a > a > a) > t a > a
 foldl1 :: (a > a > a) > t a > a
 null :: t a > Bool
 length :: t a > Int
 elem :: Eq a => a > t a > Bool
 maximum :: Ord a => t a > a
 minimum :: Ord a => t a > a
 class (Functor t, Foldable t) => Traversable (t :: Type > Type) where
 traverse :: Applicative f => (a > f b) > t a > f (t b)
 sequenceA :: Applicative f => t (f a) > f (t a)
 mapM :: Monad m => (a > m b) > t a > m (t b)
 sequence :: Monad m => t (m a) > m (t a)
 type ShowS = String > String
 type ReadS a = String > [(a, String)]
 type FilePath = String
 realToFrac :: (Real a, Fractional b) => a > b
 ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b
 otherwise :: Bool
 (++) :: [a] > [a] > [a]
 map :: (a > b) > [a] > [b]
 error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] > a
 zipWith :: (a > b > c) > [a] > [b] > [c]
 (<$>) :: Functor f => (a > b) > f a > f b
 fst :: (a, b) > a
 uncurry :: (a > b > c) > (a, b) > c
 head :: HasCallStack => [a] > a
 writeFile :: FilePath > String > IO ()
 getLine :: IO String
 putStrLn :: String > IO ()
 filter :: (a > Bool) > [a] > [a]
 cycle :: HasCallStack => [a] > [a]
 seq :: forall {r :: RuntimeRep} a (b :: TYPE r). a > b > b
 concat :: Foldable t => t [a] > [a]
 zip :: [a] > [b] > [(a, b)]
 print :: Show a => a > IO ()
 (&&) :: Bool > Bool > Bool
 () :: Bool > Bool > Bool
 not :: Bool > Bool
 errorWithoutStackTrace :: forall (r :: RuntimeRep) (a :: TYPE r). [Char] > a
 undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a
 (=<<) :: Monad m => (a > m b) > m a > m b
 const :: a > b > a
 flip :: (a > b > c) > b > a > c
 ($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b
 until :: (a > Bool) > (a > a) > a > a
 asTypeOf :: a > a > a
 maybe :: b > (a > b) > Maybe a > b
 tail :: HasCallStack => [a] > [a]
 last :: HasCallStack => [a] > a
 init :: HasCallStack => [a] > [a]
 scanl :: (b > a > b) > b > [a] > [b]
 scanl1 :: (a > a > a) > [a] > [a]
 scanr :: (a > b > b) > b > [a] > [b]
 scanr1 :: (a > a > a) > [a] > [a]
 iterate :: (a > a) > a > [a]
 repeat :: a > [a]
 replicate :: Int > a > [a]
 takeWhile :: (a > Bool) > [a] > [a]
 dropWhile :: (a > Bool) > [a] > [a]
 take :: Int > [a] > [a]
 drop :: Int > [a] > [a]
 splitAt :: Int > [a] > ([a], [a])
 span :: (a > Bool) > [a] > ([a], [a])
 break :: (a > Bool) > [a] > ([a], [a])
 reverse :: [a] > [a]
 and :: Foldable t => t Bool > Bool
 or :: Foldable t => t Bool > Bool
 any :: Foldable t => (a > Bool) > t a > Bool
 all :: Foldable t => (a > Bool) > t a > Bool
 notElem :: (Foldable t, Eq a) => a > t a > Bool
 lookup :: Eq a => a > [(a, b)] > Maybe b
 concatMap :: Foldable t => (a > [b]) > t a > [b]
 (!!) :: HasCallStack => [a] > Int > a
 zip3 :: [a] > [b] > [c] > [(a, b, c)]
 zipWith3 :: (a > b > c > d) > [a] > [b] > [c] > [d]
 unzip :: [(a, b)] > ([a], [b])
 unzip3 :: [(a, b, c)] > ([a], [b], [c])
 shows :: Show a => a > ShowS
 showChar :: Char > ShowS
 showString :: String > ShowS
 showParen :: Bool > ShowS > ShowS
 lcm :: Integral a => a > a > a
 snd :: (a, b) > b
 curry :: ((a, b) > c) > a > b > c
 lex :: ReadS String
 readParen :: Bool > ReadS a > ReadS a
 either :: (a > c) > (b > c) > Either a b > c
 reads :: Read a => ReadS a
 read :: Read a => String > a
 mapM_ :: (Foldable t, Monad m) => (a > m b) > t a > m ()
 sequence_ :: (Foldable t, Monad m) => t (m a) > m ()
 lines :: String > [String]
 unlines :: [String] > String
 words :: String > [String]
 unwords :: [String] > String
 userError :: String > IOError
 ioError :: IOError > IO a
 putChar :: Char > IO ()
 putStr :: String > IO ()
 getChar :: IO Char
 getContents :: IO String
 interact :: (String > String) > IO ()
 readFile :: FilePath > IO String
 appendFile :: FilePath > String > IO ()
 readLn :: Read a => IO a
 readIO :: Read a => String > IO a
numhask exports
module NumHask.Algebra.Additive
module NumHask.Algebra.Field
module NumHask.Algebra.Group
module NumHask.Algebra.Lattice
module NumHask.Algebra.Action
module NumHask.Algebra.Ring
module NumHask.Algebra.Metric
module NumHask.Data.Complex
module NumHask.Data.Integral
module NumHask.Data.Rational
module NumHask.Exception
rebindables
Using different types for numbers requires RebindableSyntax. This then removes baselevel stuff that has to be put back in.
ifThenElse :: Bool > a > a > a Source #
RebindableSyntax splats this, and I'm not sure where it exists in GHC land
fromList :: IsList l => [Item l] > l #
The fromList
function constructs the structure l
from the given
list of Item l
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS
constructor
Instances
module GHC.OverloadedLabels
Modules you can't live without
module Data.Bool
module Data.Kind
module GHC.Generics
module Control.Applicative
module Data.Traversable
Boolean monoid under disjunction (
).
>>>
getAny (Any True <> mempty <> Any False)
True
>>>
getAny (mconcat (map (\x > Any (even x)) [2,4,6,7,8]))
True
Instances
Data Any  Since: base4.8.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Any > c Any # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c Any # dataTypeOf :: Any > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c Any) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c Any) # gmapT :: (forall b. Data b => b > b) > Any > Any # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Any > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > Any > r # gmapQ :: (forall d. Data d => d > u) > Any > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Any > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Any > m Any # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Any > m Any # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Any > m Any #  
Monoid Any  Since: base2.1 
Semigroup Any  Since: base4.9.0.0 
Bounded Any  Since: base2.1 
Generic Any  
Read Any  Since: base2.1 
Show Any  Since: base2.1 
Eq Any  Since: base2.1 
Ord Any  Since: base2.1 
type Rep Any  Since: base4.7.0.0 
Defined in Data.Semigroup.Internal 
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:
Since: base4.9.0.0
(<>) :: a > a > a infixr 6 #
An associative operation.
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
Reduce a nonempty 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!"
stimes :: Integral b => b > 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 \(\mathcal{O}(1)\) by
picking stimes =
or stimesIdempotent
stimes =
respectively.stimesIdempotentMonoid
>>>
stimes 4 [1]
[1,1,1,1]
Instances
Semigroup All  Since: base4.9.0.0 
Semigroup Any  Since: base4.9.0.0 
Semigroup Void  Since: base4.9.0.0 
Semigroup Ordering  Since: base4.9.0.0 
Semigroup ()  Since: base4.9.0.0 
Semigroup a => Semigroup (Identity a)  Since: base4.9.0.0 
Semigroup (First a)  Since: base4.9.0.0 
Semigroup (Last a)  Since: base4.9.0.0 
Semigroup a => Semigroup (Down a)  Since: base4.11.0.0 
Semigroup (First a)  Since: base4.9.0.0 
Semigroup (Last a)  Since: base4.9.0.0 
Ord a => Semigroup (Max a)  Since: base4.9.0.0 
Ord a => Semigroup (Min a)  Since: base4.9.0.0 
Monoid m => Semigroup (WrappedMonoid m)  Since: base4.9.0.0 
Defined in Data.Semigroup (<>) :: WrappedMonoid m > WrappedMonoid m > WrappedMonoid m # sconcat :: NonEmpty (WrappedMonoid m) > WrappedMonoid m # stimes :: Integral b => b > WrappedMonoid m > WrappedMonoid m #  
Semigroup a => Semigroup (Dual a)  Since: base4.9.0.0 
Semigroup (Endo a)  Since: base4.9.0.0 
Num a => Semigroup (Product a)  Since: base4.9.0.0 
Num a => Semigroup (Sum a)  Since: base4.9.0.0 
Semigroup (NonEmpty a)  Since: base4.9.0.0 
(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)  Since: base4.17.0.0 
Defined in GHC.Generics (<>) :: Generically a > Generically a > Generically a # sconcat :: NonEmpty (Generically a) > Generically a # stimes :: Integral b => b > Generically a > Generically a #  
Semigroup p => Semigroup (Par1 p)  Since: base4.12.0.0 
Semigroup a => Semigroup (IO a)  Since: base4.10.0.0 
Additive a => Semigroup (Sum a) Source #  
Multiplicative a => Semigroup (Product a) Source #  
Semigroup a => Semigroup (Maybe a)  Since: base4.9.0.0 
Semigroup a => Semigroup (a)  Since: base4.15 
Semigroup [a]  Since: base4.9.0.0 
Semigroup (Either a b)  Since: base4.9.0.0 
Semigroup (U1 p)  Since: base4.12.0.0 
Semigroup (V1 p)  Since: base4.12.0.0 
(Semigroup a, Semigroup b) => Semigroup (a, b)  Since: base4.9.0.0 
Semigroup b => Semigroup (a > b)  Since: base4.9.0.0 
Semigroup a => Semigroup (Const a b)  Since: base4.9.0.0 
(Applicative f, Semigroup a) => Semigroup (Ap f a)  Since: base4.12.0.0 
Alternative f => Semigroup (Alt f a)  Since: base4.9.0.0 
Semigroup (f p) => Semigroup (Rec1 f p)  Since: base4.12.0.0 
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c)  Since: base4.9.0.0 
(Semigroup (f p), Semigroup (g p)) => Semigroup ((f :*: g) p)  Since: base4.12.0.0 
Semigroup c => Semigroup (K1 i c p)  Since: base4.12.0.0 
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d)  Since: base4.9.0.0 
Semigroup (f (g p)) => Semigroup ((f :.: g) p)  Since: base4.12.0.0 
Semigroup (f p) => Semigroup (M1 i c f p)  Since: base4.12.0.0 
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e)  Since: base4.9.0.0 
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 nonNothing
,
thus x <> Data.Monoid.Last Nothing = x
.
Instances
MonadFix Last  Since: base4.9.0.0 
Defined in Data.Semigroup  
Foldable Last  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Last m > m # foldMap :: Monoid m => (a > m) > Last a > m # foldMap' :: Monoid m => (a > m) > Last a > m # foldr :: (a > b > b) > b > Last a > b # foldr' :: (a > b > b) > b > Last a > b # foldl :: (b > a > b) > b > Last a > b # foldl' :: (b > a > b) > b > Last a > b # foldr1 :: (a > a > a) > Last a > a # foldl1 :: (a > a > a) > Last a > a # elem :: Eq a => a > Last a > Bool # maximum :: Ord a => Last a > a #  
Traversable Last  Since: base4.9.0.0 
Applicative Last  Since: base4.9.0.0 
Functor Last  Since: base4.9.0.0 
Monad Last  Since: base4.9.0.0 
Generic1 Last  
Data a => Data (Last a)  Since: base4.9.0.0 
Defined in Data.Semigroup gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Last a > c (Last a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Last a) # toConstr :: Last a > Constr # dataTypeOf :: Last a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Last a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Last a)) # gmapT :: (forall b. Data b => b > b) > Last a > Last a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Last a > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > Last a > r # gmapQ :: (forall d. Data d => d > u) > Last a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Last a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Last a > m (Last a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Last a > m (Last a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Last a > m (Last a) #  
Semigroup (Last a)  Since: base4.9.0.0 
Bounded a => Bounded (Last a)  Since: base4.9.0.0 
Enum a => Enum (Last a)  Since: base4.9.0.0 
Defined in Data.Semigroup  
Generic (Last a)  
Read a => Read (Last a)  Since: base4.9.0.0 
Show a => Show (Last a)  Since: base4.9.0.0 
Eq a => Eq (Last a)  Since: base4.9.0.0 
Ord a => Ord (Last a)  Since: base4.9.0.0 
type Rep1 Last  Since: base4.9.0.0 
Defined in Data.Semigroup  
type Rep (Last a)  Since: base4.9.0.0 
Defined in Data.Semigroup 
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 nonNothing
,
thus Data.Monoid.First Nothing <> x = x
.
Instances
MonadFix First  Since: base4.9.0.0 
Defined in Data.Semigroup  
Foldable First  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => First m > m # foldMap :: Monoid m => (a > m) > First a > m # foldMap' :: Monoid m => (a > m) > First a > m # foldr :: (a > b > b) > b > First a > b # foldr' :: (a > b > b) > b > First a > b # foldl :: (b > a > b) > b > First a > b # foldl' :: (b > a > b) > b > First a > b # foldr1 :: (a > a > a) > First a > a # foldl1 :: (a > a > a) > First a > a # elem :: Eq a => a > First a > Bool # maximum :: Ord a => First a > a # minimum :: Ord a => First a > a #  
Traversable First  Since: base4.9.0.0 
Applicative First  Since: base4.9.0.0 
Functor First  Since: base4.9.0.0 
Monad First  Since: base4.9.0.0 
Generic1 First  
Data a => Data (First a)  Since: base4.9.0.0 
Defined in Data.Semigroup gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > First a > c (First a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (First a) # toConstr :: First a > Constr # dataTypeOf :: First a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (First a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (First a)) # gmapT :: (forall b. Data b => b > b) > First a > First a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > First a > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > First a > r # gmapQ :: (forall d. Data d => d > u) > First a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > First a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > First a > m (First a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > First a > m (First a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > First a > m (First a) #  
Semigroup (First a)  Since: base4.9.0.0 
Bounded a => Bounded (First a)  Since: base4.9.0.0 
Enum a => Enum (First a)  Since: base4.9.0.0 
Generic (First a)  
Read a => Read (First a)  Since: base4.9.0.0 
Show a => Show (First a)  Since: base4.9.0.0 
Eq a => Eq (First a)  Since: base4.9.0.0 
Ord a => Ord (First a)  Since: base4.9.0.0 
type Rep1 First  Since: base4.9.0.0 
Defined in Data.Semigroup  
type Rep (First a)  Since: base4.9.0.0 
Defined in Data.Semigroup 
Boolean monoid under conjunction (&&
).
>>>
getAll (All True <> mempty <> All False)
False
>>>
getAll (mconcat (map (\x > All (even x)) [2,4,6,7,8]))
False
Instances
Data All  Since: base4.8.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > All > c All # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c All # dataTypeOf :: All > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c All) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c All) # gmapT :: (forall b. Data b => b > b) > All > All # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > All > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > All > r # gmapQ :: (forall d. Data d => d > u) > All > [u] # gmapQi :: Int > (forall d. Data d => d > u) > All > u # gmapM :: Monad m => (forall d. Data d => d > m d) > All > m All # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > All > m All # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > All > m All #  
Monoid All  Since: base2.1 
Semigroup All  Since: base4.9.0.0 
Bounded All  Since: base2.1 
Generic All  
Read All  Since: base2.1 
Show All  Since: base2.1 
Eq All  Since: base2.1 
Ord All  Since: base2.1 
type Rep All  Since: base4.7.0.0 
Defined in Data.Semigroup.Internal 
The monoid of endomorphisms under composition.
>>>
let computation = Endo ("Hello, " ++) <> Endo (++ "!")
>>>
appEndo computation "Haskell"
"Hello, Haskell!"
The dual of a Monoid
, obtained by swapping the arguments of mappend
.
>>>
getDual (mappend (Dual "Hello") (Dual "World"))
"WorldHello"
Instances
Foldable Dual  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Dual m > m # foldMap :: Monoid m => (a > m) > Dual a > m # foldMap' :: Monoid m => (a > m) > Dual a > m # foldr :: (a > b > b) > b > Dual a > b # foldr' :: (a > b > b) > b > Dual a > b # foldl :: (b > a > b) > b > Dual a > b # foldl' :: (b > a > b) > b > Dual a > b # foldr1 :: (a > a > a) > Dual a > a # foldl1 :: (a > a > a) > Dual a > a # elem :: Eq a => a > Dual a > Bool # maximum :: Ord a => Dual a > a #  
Traversable Dual  Since: base4.8.0.0 
Applicative Dual  Since: base4.8.0.0 
Functor Dual  Since: base4.8.0.0 
Monad Dual  Since: base4.8.0.0 
Generic1 Dual  
Data a => Data (Dual a)  Since: base4.8.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Dual a > c (Dual a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Dual a) # toConstr :: Dual a > Constr # dataTypeOf :: Dual a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Dual a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Dual a)) # gmapT :: (forall b. Data b => b > b) > Dual a > Dual a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Dual a > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > Dual a > r # gmapQ :: (forall d. Data d => d > u) > Dual a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Dual a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Dual a > m (Dual a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Dual a > m (Dual a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Dual a > m (Dual a) #  
Monoid a => Monoid (Dual a)  Since: base2.1 
Semigroup a => Semigroup (Dual a)  Since: base4.9.0.0 
Bounded a => Bounded (Dual a)  Since: base2.1 
Generic (Dual a)  
Read a => Read (Dual a)  Since: base2.1 
Show a => Show (Dual a)  Since: base2.1 
Eq a => Eq (Dual a)  Since: base2.1 
Ord a => Ord (Dual a)  Since: base2.1 
type Rep1 Dual  Since: base4.7.0.0 
Defined in Data.Semigroup.Internal  
type Rep (Dual a)  Since: base4.7.0.0 
Defined in Data.Semigroup.Internal 
newtype WrappedMonoid m #
Provide a Semigroup for an arbitrary Monoid.
NOTE: This is not needed anymore since Semigroup
became a superclass of
Monoid
in base4.11 and this newtype be deprecated at some point in the future.
WrapMonoid  

Instances
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
Instances
Bifoldable Arg  Since: base4.10.0.0 
Bifunctor Arg  Since: base4.9.0.0 
Bitraversable Arg  Since: base4.10.0.0 
Defined in Data.Semigroup bitraverse :: Applicative f => (a > f c) > (b > f d) > Arg a b > f (Arg c d) #  
Generic1 (Arg a :: Type > Type)  
Foldable (Arg a)  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Arg a m > m # foldMap :: Monoid m => (a0 > m) > Arg a a0 > m # foldMap' :: Monoid m => (a0 > m) > Arg a a0 > m # foldr :: (a0 > b > b) > b > Arg a a0 > b # foldr' :: (a0 > b > b) > b > Arg a a0 > b # foldl :: (b > a0 > b) > b > Arg a a0 > b # foldl' :: (b > a0 > b) > b > Arg a a0 > b # foldr1 :: (a0 > a0 > a0) > Arg a a0 > a0 # foldl1 :: (a0 > a0 > a0) > Arg a a0 > a0 # elem :: Eq a0 => a0 > Arg a a0 > Bool # maximum :: Ord a0 => Arg a a0 > a0 # minimum :: Ord a0 => Arg a a0 > a0 #  
Traversable (Arg a)  Since: base4.9.0.0 
Functor (Arg a)  Since: base4.9.0.0 
(Data a, Data b) => Data (Arg a b)  Since: base4.9.0.0 
Defined in Data.Semigroup gfoldl :: (forall d b0. Data d => c (d > b0) > d > c b0) > (forall g. g > c g) > Arg a b > c (Arg a b) # gunfold :: (forall b0 r. Data b0 => c (b0 > r) > c r) > (forall r. r > c r) > Constr > c (Arg a b) # toConstr :: Arg a b > Constr # dataTypeOf :: Arg a b > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Arg a b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Arg a b)) # gmapT :: (forall b0. Data b0 => b0 > b0) > Arg a b > Arg a b # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Arg a b > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > Arg a b > r # gmapQ :: (forall d. Data d => d > u) > Arg a b > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Arg a b > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Arg a b > m (Arg a b) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Arg a b > m (Arg a b) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Arg a b > m (Arg a b) #  
Generic (Arg a b)  
(Read a, Read b) => Read (Arg a b)  Since: base4.9.0.0 
(Show a, Show b) => Show (Arg a b)  Since: base4.9.0.0 
Eq a => Eq (Arg a b)  Since: base4.9.0.0 
Ord a => Ord (Arg a b)  Since: base4.9.0.0 
type Rep1 (Arg a :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Semigroup type Rep1 (Arg a :: Type > Type) = D1 ('MetaData "Arg" "Data.Semigroup" "base" 'False) (C1 ('MetaCons "Arg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))  
type Rep (Arg a b)  Since: base4.9.0.0 
Defined in Data.Semigroup type Rep (Arg a b) = D1 ('MetaData "Arg" "Data.Semigroup" "base" 'False) (C1 ('MetaCons "Arg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b))) 
stimesIdempotent :: Integral b => b > a > a #
stimesIdempotentMonoid :: (Integral b, Monoid a) => b > a > a #
stimesMonoid :: (Integral b, Monoid a) => b > a > a #
diff :: Semigroup m => m > Endo m #
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!"
mtimesDefault :: (Integral b, Monoid a) => b > a > a #
Repeat a value n
times.
mtimesDefault n a = a <> a <> ... <> a  using <> (n1) 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.
module Data.Maybe
Data.Function
($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, rightassociative 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 higherorder situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs
Note that (
is representationpolymorphic in its result type, so that
$
)foo
where $
Truefoo :: Bool > Int#
is welltyped.
const x y
always evaluates to x
, ignoring its second argument.
>>>
const 42 "hello"
42
>>>
map (const 42) [0..3]
[42,42,42,42]
flip :: (a > b > c) > b > a > c #
takes its (first) two arguments in the reverse order of flip
ff
.
>>>
flip (++) "hello" "world"
"worldhello"
is the least fixed point of the function fix
ff
,
i.e. the least defined x
such that f x = x
.
For example, we can write the factorial function using direct recursion as
>>>
let fac n = if n <= 1 then 1 else n * fac (n1) in fac 5
120
This uses the fact that Haskell’s let
introduces recursive bindings. We can
rewrite this definition using fix
,
>>>
fix (\rec n > if n <= 1 then 1 else n * rec (n1)) 5
120
Instead of making a recursive call, we introduce a dummy parameter rec
;
when used within fix
, this parameter then refers to fix
’s argument, hence
the recursion is reintroduced.
Control.Category
module Control.Category
Data.Foldable
class Foldable (t :: Type > Type) where #
The Foldable class represents data structures that can be reduced to a summary value one element at a time. Strict leftassociative folds are a good fit for spaceefficient reduction, while lazy rightassociative folds are a good fit for corecursive iteration, or for folds that shortcircuit 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.
For the class laws see the Laws section of Data.Foldable.
fold :: Monoid m => t m > m #
Given a structure with elements whose type is a Monoid
, combine them
via the monoid's (
operator. This fold is rightassociative and
lazy in the accumulator. When you need a strict leftassociative fold,
use <>
)foldMap'
instead, with id
as the map.
Examples
Basic usage:
>>>
fold [[1, 2, 3], [4, 5], [6], []]
[1,2,3,4,5,6]
>>>
fold $ Node (Leaf (Sum 1)) (Sum 3) (Leaf (Sum 5))
Sum {getSum = 9}
Folds of unbounded structures do not terminate when the monoid's
(
operator is strict:<>
)
>>>
fold (repeat Nothing)
* Hangs forever *
Lazy corecursive folds of unbounded structures are fine:
>>>
take 12 $ fold $ map (\i > [i..i+2]) [0..]
[0,1,2,1,2,3,2,3,4,3,4,5]>>>
sum $ take 4000000 $ fold $ map (\i > [i..i+2]) [0..]
2666668666666
foldMap :: Monoid m => (a > m) > t a > m #
Map each element of the structure into a monoid, and combine the
results with (
. This fold is rightassociative and lazy in the
accumulator. For strict leftassociative 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' :: Monoid m => (a > m) > t a > m #
A leftassociative variant of foldMap
that is strict in the
accumulator. Use this method for strict reduction when partial
results are merged via (
.<>
)
Examples
Define a Monoid
over finite bit strings under xor
. Use it to
strictly compute the xor
of a list of Int
values.
>>>
:set XGeneralizedNewtypeDeriving
>>>
import Data.Bits (Bits, FiniteBits, xor, zeroBits)
>>>
import Data.Foldable (foldMap')
>>>
import Numeric (showHex)
>>>
>>>
newtype X a = X a deriving (Eq, Bounded, Enum, Bits, FiniteBits)
>>>
instance Bits a => Semigroup (X a) where X a <> X b = X (a `xor` b)
>>>
instance Bits a => Monoid (X a) where mempty = X zeroBits
>>>
>>>
let bits :: [Int]; bits = [0xcafe, 0xfeed, 0xdeaf, 0xbeef, 0x5411]
>>>
(\ (X a) > showString "0x" . showHex a $ "") $ foldMap' X bits
"0x42"
Since: base4.13.0.0
foldr :: (a > b > b) > b > t a > b #
Rightassociative 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 rightidentity 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:
 the folding function is shortcircuiting
 the folding function is lazy on its second argument
Shortcircuiting
(
shortcircuits 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' :: (a > b > b) > b > t a > b #
foldr'
is a variant of foldr
that performs strict reduction from
right to left, i.e. starting with the rightmost element. The input
structure must be finite, otherwise foldr'
runs out of space
(diverges).
If you want a strict right fold in constant space, you need a structure
that supports faster than O(n) access to the rightmost element, such
as Seq
from the containers
package.
This method does not run in constant space for structures such as lists
that don't support efficient righttoleft iteration and so require
O(n) space to perform righttoleft reduction. Use of this method
with such a structure is a hint that the chosen structure may be a poor
fit for the task at hand. If the order in which the elements are
combined is not important, use foldl'
instead.
Since: base4.6.0.0
foldl :: (b > a > b) > b > t a > b #
Leftassociative fold of a structure, lazy in the accumulator. This is rarely what you want, but can work well for structures with efficient righttoleft 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 leftidentity 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 leftassociative folds,
foldl
will diverge if given an infinite list.
If you want an efficient strict leftfold, 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 outsidein.
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' :: (b > a > b) > b > t a > b #
Leftassociative 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
Since: base4.6.0.0
foldr1 :: (a > a > a) > t a > a #
A variant of foldr
that has no base case,
and thus may only be applied to nonempty structures.
This function is nontotal 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 *
foldl1 :: (a > a > a) > t a > a #
A variant of foldl
that has no base case,
and thus may only be applied to nonempty structures.
This function is nontotal 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 *
List of elements of a structure, from left to right. If the entire list is intended to be reduced via a fold, just fold the structure directly bypassing the list.
Examples
Basic usage:
>>>
toList Nothing
[]
>>>
toList (Just 42)
[42]
>>>
toList (Left "foo")
[]
>>>
toList (Node (Leaf 5) 17 (Node Empty 12 (Leaf 8)))
[5,17,12,8]
For lists, toList
is the identity:
>>>
toList [1, 2, 3]
[1,2,3]
Since: base4.8.0.0
Test whether the structure is empty. The default implementation is Leftassociative 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 nondefault 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
Since: base4.8.0.0
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 elementbyelement counting, should provide a specialised
implementation.
Examples
Basic usage:
>>>
length []
0
>>>
length ['a', 'b', 'c']
3>>>
length [1..]
* Hangs forever *
Since: base4.8.0.0
elem :: Eq a => a > t a > Bool infix 4 #
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 soughtafter value exists at a finite distance
from the left side of the structure:
>>>
3 `elem` [1..]
True
>>>
3 `elem` ([4..] ++ [3])
* Hangs forever *
Since: base4.8.0.0
maximum :: Ord a => t a > a #
The largest element of a nonempty structure.
This function is nontotal 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 possiblyempty structures like lists.
Since: base4.8.0.0
minimum :: Ord a => t a > a #
The least element of a nonempty structure.
This function is nontotal 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 possiblyempty structures like lists.
Since: base4.8.0.0
Instances
Foldable ZipList  Since: base4.9.0.0 
Defined in Control.Applicative fold :: Monoid m => ZipList m > m # foldMap :: Monoid m => (a > m) > ZipList a > m # foldMap' :: Monoid m => (a > m) > ZipList a > m # foldr :: (a > b > b) > b > ZipList a > b # foldr' :: (a > b > b) > b > ZipList a > b # foldl :: (b > a > b) > b > ZipList a > b # foldl' :: (b > a > b) > b > ZipList a > b # foldr1 :: (a > a > a) > ZipList a > a # foldl1 :: (a > a > a) > ZipList a > a # elem :: Eq a => a > ZipList a > Bool # maximum :: Ord a => ZipList a > a # minimum :: Ord a => ZipList a > a #  
Foldable Identity  Since: base4.8.0.0 
Defined in Data.Functor.Identity fold :: Monoid m => Identity m > m # foldMap :: Monoid m => (a > m) > Identity a > m # foldMap' :: Monoid m => (a > m) > Identity a > m # foldr :: (a > b > b) > b > Identity a > b # foldr' :: (a > b > b) > b > Identity a > b # foldl :: (b > a > b) > b > Identity a > b # foldl' :: (b > a > b) > b > Identity a > b # foldr1 :: (a > a > a) > Identity a > a # foldl1 :: (a > a > a) > Identity a > a # elem :: Eq a => a > Identity a > Bool # maximum :: Ord a => Identity a > a # minimum :: Ord a => Identity a > a #  
Foldable First  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => First m > m # foldMap :: Monoid m => (a > m) > First a > m # foldMap' :: Monoid m => (a > m) > First a > m # foldr :: (a > b > b) > b > First a > b # foldr' :: (a > b > b) > b > First a > b # foldl :: (b > a > b) > b > First a > b # foldl' :: (b > a > b) > b > First a > b # foldr1 :: (a > a > a) > First a > a # foldl1 :: (a > a > a) > First a > a # elem :: Eq a => a > First a > Bool # maximum :: Ord a => First a > a # minimum :: Ord a => First a > a #  
Foldable Last  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Last m > m # foldMap :: Monoid m => (a > m) > Last a > m # foldMap' :: Monoid m => (a > m) > Last a > m # foldr :: (a > b > b) > b > Last a > b # foldr' :: (a > b > b) > b > Last a > b # foldl :: (b > a > b) > b > Last a > b # foldl' :: (b > a > b) > b > Last a > b # foldr1 :: (a > a > a) > Last a > a # foldl1 :: (a > a > a) > Last a > a # elem :: Eq a => a > Last a > Bool # maximum :: Ord a => Last a > a #  
Foldable Down  Since: base4.12.0.0 
Defined in Data.Foldable fold :: Monoid m => Down m > m # foldMap :: Monoid m => (a > m) > Down a > m # foldMap' :: Monoid m => (a > m) > Down a > m # foldr :: (a > b > b) > b > Down a > b # foldr' :: (a > b > b) > b > Down a > b # foldl :: (b > a > b) > b > Down a > b # foldl' :: (b > a > b) > b > Down a > b # foldr1 :: (a > a > a) > Down a > a # foldl1 :: (a > a > a) > Down a > a # elem :: Eq a => a > Down a > Bool # maximum :: Ord a => Down a > a #  
Foldable First  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => First m > m # foldMap :: Monoid m => (a > m) > First a > m # foldMap' :: Monoid m => (a > m) > First a > m # foldr :: (a > b > b) > b > First a > b # foldr' :: (a > b > b) > b > First a > b # foldl :: (b > a > b) > b > First a > b # foldl' :: (b > a > b) > b > First a > b # foldr1 :: (a > a > a) > First a > a # foldl1 :: (a > a > a) > First a > a # elem :: Eq a => a > First a > Bool # maximum :: Ord a => First a > a # minimum :: Ord a => First a > a #  
Foldable Last  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Last m > m # foldMap :: Monoid m => (a > m) > Last a > m # foldMap' :: Monoid m => (a > m) > Last a > m # foldr :: (a > b > b) > b > Last a > b # foldr' :: (a > b > b) > b > Last a > b # foldl :: (b > a > b) > b > Last a > b # foldl' :: (b > a > b) > b > Last a > b # foldr1 :: (a > a > a) > Last a > a # foldl1 :: (a > a > a) > Last a > a # elem :: Eq a => a > Last a > Bool # maximum :: Ord a => Last a > a #  
Foldable Max  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Max m > m # foldMap :: Monoid m => (a > m) > Max a > m # foldMap' :: Monoid m => (a > m) > Max a > m # foldr :: (a > b > b) > b > Max a > b # foldr' :: (a > b > b) > b > Max a > b # foldl :: (b > a > b) > b > Max a > b # foldl' :: (b > a > b) > b > Max a > b # foldr1 :: (a > a > a) > Max a > a # foldl1 :: (a > a > a) > Max a > a # elem :: Eq a => a > Max a > Bool # maximum :: Ord a => Max a > a #  
Foldable Min  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Min m > m # foldMap :: Monoid m => (a > m) > Min a > m # foldMap' :: Monoid m => (a > m) > Min a > m # foldr :: (a > b > b) > b > Min a > b # foldr' :: (a > b > b) > b > Min a > b # foldl :: (b > a > b) > b > Min a > b # foldl' :: (b > a > b) > b > Min a > b # foldr1 :: (a > a > a) > Min a > a # foldl1 :: (a > a > a) > Min a > a # elem :: Eq a => a > Min a > Bool # maximum :: Ord a => Min a > a #  
Foldable Dual  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Dual m > m # foldMap :: Monoid m => (a > m) > Dual a > m # foldMap' :: Monoid m => (a > m) > Dual a > m # foldr :: (a > b > b) > b > Dual a > b # foldr' :: (a > b > b) > b > Dual a > b # foldl :: (b > a > b) > b > Dual a > b # foldl' :: (b > a > b) > b > Dual a > b # foldr1 :: (a > a > a) > Dual a > a # foldl1 :: (a > a > a) > Dual a > a # elem :: Eq a => a > Dual a > Bool # maximum :: Ord a => Dual a > a #  
Foldable Product  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Product m > m # foldMap :: Monoid m => (a > m) > Product a > m # foldMap' :: Monoid m => (a > m) > Product a > m # foldr :: (a > b > b) > b > Product a > b # foldr' :: (a > b > b) > b > Product a > b # foldl :: (b > a > b) > b > Product a > b # foldl' :: (b > a > b) > b > Product a > b # foldr1 :: (a > a > a) > Product a > a # foldl1 :: (a > a > a) > Product a > a # elem :: Eq a => a > Product a > Bool # maximum :: Ord a => Product a > a # minimum :: Ord a => Product a > a #  
Foldable Sum  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Sum m > m # foldMap :: Monoid m => (a > m) > Sum a > m # foldMap' :: Monoid m => (a > m) > Sum a > m # foldr :: (a > b > b) > b > Sum a > b # foldr' :: (a > b > b) > b > Sum a > b # foldl :: (b > a > b) > b > Sum a > b # foldl' :: (b > a > b) > b > Sum a > b # foldr1 :: (a > a > a) > Sum a > a # foldl1 :: (a > a > a) > Sum a > a # elem :: Eq a => a > Sum a > Bool # maximum :: Ord a => Sum a > a #  
Foldable NonEmpty  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => NonEmpty m > m # foldMap :: Monoid m => (a > m) > NonEmpty a > m # foldMap' :: Monoid m => (a > m) > NonEmpty a > m # foldr :: (a > b > b) > b > NonEmpty a > b # foldr' :: (a > b > b) > b > NonEmpty a > b # foldl :: (b > a > b) > b > NonEmpty a > b # foldl' :: (b > a > b) > b > NonEmpty a > b # foldr1 :: (a > a > a) > NonEmpty a > a # foldl1 :: (a > a > a) > NonEmpty a > a # elem :: Eq a => a > NonEmpty a > Bool # maximum :: Ord a => NonEmpty a > a # minimum :: Ord a => NonEmpty a > a #  
Foldable Par1  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => Par1 m > m # foldMap :: Monoid m => (a > m) > Par1 a > m # foldMap' :: Monoid m => (a > m) > Par1 a > m # foldr :: (a > b > b) > b > Par1 a > b # foldr' :: (a > b > b) > b > Par1 a > b # foldl :: (b > a > b) > b > Par1 a > b # foldl' :: (b > a > b) > b > Par1 a > b # foldr1 :: (a > a > a) > Par1 a > a # foldl1 :: (a > a > a) > Par1 a > a # elem :: Eq a => a > Par1 a > Bool # maximum :: Ord a => Par1 a > a #  
Foldable Maybe  Since: base2.1 
Defined in Data.Foldable fold :: Monoid m => Maybe m > m # foldMap :: Monoid m => (a > m) > Maybe a > m # foldMap' :: Monoid m => (a > m) > Maybe a > m # foldr :: (a > b > b) > b > Maybe a > b # foldr' :: (a > b > b) > b > Maybe a > b # foldl :: (b > a > b) > b > Maybe a > b # foldl' :: (b > a > b) > b > Maybe a > b # foldr1 :: (a > a > a) > Maybe a > a # foldl1 :: (a > a > a) > Maybe a > a # elem :: Eq a => a > Maybe a > Bool # maximum :: Ord a => Maybe a > a # minimum :: Ord a => Maybe a > a #  
Foldable Solo  Since: base4.15 
Defined in Data.Foldable fold :: Monoid m => Solo m > m # foldMap :: Monoid m => (a > m) > Solo a > m # foldMap' :: Monoid m => (a > m) > Solo a > m # foldr :: (a > b > b) > b > Solo a > b # foldr' :: (a > b > b) > b > Solo a > b # foldl :: (b > a > b) > b > Solo a > b # foldl' :: (b > a > b) > b > Solo a > b # foldr1 :: (a > a > a) > Solo a > a # foldl1 :: (a > a > a) > Solo a > a # elem :: Eq a => a > Solo a > Bool # maximum :: Ord a => Solo a > a #  
Foldable List  Since: base2.1 
Defined in Data.Foldable fold :: Monoid m => [m] > m # foldMap :: Monoid m => (a > m) > [a] > m # foldMap' :: Monoid m => (a > m) > [a] > m # foldr :: (a > b > b) > b > [a] > b # foldr' :: (a > b > b) > b > [a] > b # foldl :: (b > a > b) > b > [a] > b # foldl' :: (b > a > b) > b > [a] > b # foldr1 :: (a > a > a) > [a] > a # foldl1 :: (a > a > a) > [a] > a # elem :: Eq a => a > [a] > Bool # maximum :: Ord a => [a] > a #  
Foldable (Either a)  Since: base4.7.0.0 
Defined in Data.Foldable fold :: Monoid m => Either a m > m # foldMap :: Monoid m => (a0 > m) > Either a a0 > m # foldMap' :: Monoid m => (a0 > m) > Either a a0 > m # foldr :: (a0 > b > b) > b > Either a a0 > b # foldr' :: (a0 > b > b) > b > Either a a0 > b # foldl :: (b > a0 > b) > b > Either a a0 > b # foldl' :: (b > a0 > b) > b > Either a a0 > b # foldr1 :: (a0 > a0 > a0) > Either a a0 > a0 # foldl1 :: (a0 > a0 > a0) > Either a a0 > a0 # toList :: Either a a0 > [a0] # length :: Either a a0 > Int # elem :: Eq a0 => a0 > Either a a0 > Bool # maximum :: Ord a0 => Either a a0 > a0 # minimum :: Ord a0 => Either a a0 > a0 #  
Foldable (Proxy :: Type > Type)  Since: base4.7.0.0 
Defined in Data.Foldable fold :: Monoid m => Proxy m > m # foldMap :: Monoid m => (a > m) > Proxy a > m # foldMap' :: Monoid m => (a > m) > Proxy a > m # foldr :: (a > b > b) > b > Proxy a > b # foldr' :: (a > b > b) > b > Proxy a > b # foldl :: (b > a > b) > b > Proxy a > b # foldl' :: (b > a > b) > b > Proxy a > b # foldr1 :: (a > a > a) > Proxy a > a # foldl1 :: (a > a > a) > Proxy a > a # elem :: Eq a => a > Proxy a > Bool # maximum :: Ord a => Proxy a > a # minimum :: Ord a => Proxy a > a #  
Foldable (Arg a)  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Arg a m > m # foldMap :: Monoid m => (a0 > m) > Arg a a0 > m # foldMap' :: Monoid m => (a0 > m) > Arg a a0 > m # foldr :: (a0 > b > b) > b > Arg a a0 > b # foldr' :: (a0 > b > b) > b > Arg a a0 > b # foldl :: (b > a0 > b) > b > Arg a a0 > b # foldl' :: (b > a0 > b) > b > Arg a a0 > b # foldr1 :: (a0 > a0 > a0) > Arg a a0 > a0 # foldl1 :: (a0 > a0 > a0) > Arg a a0 > a0 # elem :: Eq a0 => a0 > Arg a a0 > Bool # maximum :: Ord a0 => Arg a a0 > a0 # minimum :: Ord a0 => Arg a a0 > a0 #  
Foldable (Array i)  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Array i m > m # foldMap :: Monoid m => (a > m) > Array i a > m # foldMap' :: Monoid m => (a > m) > Array i a > m # foldr :: (a > b > b) > b > Array i a > b # foldr' :: (a > b > b) > b > Array i a > b # foldl :: (b > a > b) > b > Array i a > b # foldl' :: (b > a > b) > b > Array i a > b # foldr1 :: (a > a > a) > Array i a > a # foldl1 :: (a > a > a) > Array i a > a # elem :: Eq a => a > Array i a > Bool # maximum :: Ord a => Array i a > a # minimum :: Ord a => Array i a > a #  
Foldable (U1 :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => U1 m > m # foldMap :: Monoid m => (a > m) > U1 a > m # foldMap' :: Monoid m => (a > m) > U1 a > m # foldr :: (a > b > b) > b > U1 a > b # foldr' :: (a > b > b) > b > U1 a > b # foldl :: (b > a > b) > b > U1 a > b # foldl' :: (b > a > b) > b > U1 a > b # foldr1 :: (a > a > a) > U1 a > a # foldl1 :: (a > a > a) > U1 a > a # elem :: Eq a => a > U1 a > Bool # maximum :: Ord a => U1 a > a #  
Foldable (UAddr :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UAddr m > m # foldMap :: Monoid m => (a > m) > UAddr a > m # foldMap' :: Monoid m => (a > m) > UAddr a > m # foldr :: (a > b > b) > b > UAddr a > b # foldr' :: (a > b > b) > b > UAddr a > b # foldl :: (b > a > b) > b > UAddr a > b # foldl' :: (b > a > b) > b > UAddr a > b # foldr1 :: (a > a > a) > UAddr a > a # foldl1 :: (a > a > a) > UAddr a > a # elem :: Eq a => a > UAddr a > Bool # maximum :: Ord a => UAddr a > a # minimum :: Ord a => UAddr a > a #  
Foldable (UChar :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UChar m > m # foldMap :: Monoid m => (a > m) > UChar a > m # foldMap' :: Monoid m => (a > m) > UChar a > m # foldr :: (a > b > b) > b > UChar a > b # foldr' :: (a > b > b) > b > UChar a > b # foldl :: (b > a > b) > b > UChar a > b # foldl' :: (b > a > b) > b > UChar a > b # foldr1 :: (a > a > a) > UChar a > a # foldl1 :: (a > a > a) > UChar a > a # elem :: Eq a => a > UChar a > Bool # maximum :: Ord a => UChar a > a # minimum :: Ord a => UChar a > a #  
Foldable (UDouble :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UDouble m > m # foldMap :: Monoid m => (a > m) > UDouble a > m # foldMap' :: Monoid m => (a > m) > UDouble a > m # foldr :: (a > b > b) > b > UDouble a > b # foldr' :: (a > b > b) > b > UDouble a > b # foldl :: (b > a > b) > b > UDouble a > b # foldl' :: (b > a > b) > b > UDouble a > b # foldr1 :: (a > a > a) > UDouble a > a # foldl1 :: (a > a > a) > UDouble a > a # elem :: Eq a => a > UDouble a > Bool # maximum :: Ord a => UDouble a > a # minimum :: Ord a => UDouble a > a #  
Foldable (UFloat :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UFloat m > m # foldMap :: Monoid m => (a > m) > UFloat a > m # foldMap' :: Monoid m => (a > m) > UFloat a > m # foldr :: (a > b > b) > b > UFloat a > b # foldr' :: (a > b > b) > b > UFloat a > b # foldl :: (b > a > b) > b > UFloat a > b # foldl' :: (b > a > b) > b > UFloat a > b # foldr1 :: (a > a > a) > UFloat a > a # foldl1 :: (a > a > a) > UFloat a > a # elem :: Eq a => a > UFloat a > Bool # maximum :: Ord a => UFloat a > a # minimum :: Ord a => UFloat a > a #  
Foldable (UInt :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UInt m > m # foldMap :: Monoid m => (a > m) > UInt a > m # foldMap' :: Monoid m => (a > m) > UInt a > m # foldr :: (a > b > b) > b > UInt a > b # foldr' :: (a > b > b) > b > UInt a > b # foldl :: (b > a > b) > b > UInt a > b # foldl' :: (b > a > b) > b > UInt a > b # foldr1 :: (a > a > a) > UInt a > a # foldl1 :: (a > a > a) > UInt a > a # elem :: Eq a => a > UInt a > Bool # maximum :: Ord a => UInt a > a #  
Foldable (UWord :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UWord m > m # foldMap :: Monoid m => (a > m) > UWord a > m # foldMap' :: Monoid m => (a > m) > UWord a > m # foldr :: (a > b > b) > b > UWord a > b # foldr' :: (a > b > b) > b > UWord a > b # foldl :: (b > a > b) > b > UWord a > b # foldl' :: (b > a > b) > b > UWord a > b # foldr1 :: (a > a > a) > UWord a > a # foldl1 :: (a > a > a) > UWord a > a # elem :: Eq a => a > UWord a > Bool # maximum :: Ord a => UWord a > a # minimum :: Ord a => UWord a > a #  
Foldable (V1 :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => V1 m > m # foldMap :: Monoid m => (a > m) > V1 a > m # foldMap' :: Monoid m => (a > m) > V1 a > m # foldr :: (a > b > b) > b > V1 a > b # foldr' :: (a > b > b) > b > V1 a > b # foldl :: (b > a > b) > b > V1 a > b # foldl' :: (b > a > b) > b > V1 a > b # foldr1 :: (a > a > a) > V1 a > a # foldl1 :: (a > a > a) > V1 a > a # elem :: Eq a => a > V1 a > Bool # maximum :: Ord a => V1 a > a #  
Foldable ((,) a)  Since: base4.7.0.0 
Defined in Data.Foldable fold :: Monoid m => (a, m) > m # foldMap :: Monoid m => (a0 > m) > (a, a0) > m # foldMap' :: Monoid m => (a0 > m) > (a, a0) > m # foldr :: (a0 > b > b) > b > (a, a0) > b # foldr' :: (a0 > b > b) > b > (a, a0) > b # foldl :: (b > a0 > b) > b > (a, a0) > b # foldl' :: (b > a0 > b) > b > (a, a0) > b # foldr1 :: (a0 > a0 > a0) > (a, a0) > a0 # foldl1 :: (a0 > a0 > a0) > (a, a0) > a0 # elem :: Eq a0 => a0 > (a, a0) > Bool # maximum :: Ord a0 => (a, a0) > a0 # minimum :: Ord a0 => (a, a0) > a0 #  
Foldable (Const m :: Type > Type)  Since: base4.7.0.0 
Defined in Data.Functor.Const fold :: Monoid m0 => Const m m0 > m0 # foldMap :: Monoid m0 => (a > m0) > Const m a > m0 # foldMap' :: Monoid m0 => (a > m0) > Const m a > m0 # foldr :: (a > b > b) > b > Const m a > b # foldr' :: (a > b > b) > b > Const m a > b # foldl :: (b > a > b) > b > Const m a > b # foldl' :: (b > a > b) > b > Const m a > b # foldr1 :: (a > a > a) > Const m a > a # foldl1 :: (a > a > a) > Const m a > a # elem :: Eq a => a > Const m a > Bool # maximum :: Ord a => Const m a > a # minimum :: Ord a => Const m a > a #  
Foldable f => Foldable (Ap f)  Since: base4.12.0.0 
Defined in Data.Foldable fold :: Monoid m => Ap f m > m # foldMap :: Monoid m => (a > m) > Ap f a > m # foldMap' :: Monoid m => (a > m) > Ap f a > m # foldr :: (a > b > b) > b > Ap f a > b # foldr' :: (a > b > b) > b > Ap f a > b # foldl :: (b > a > b) > b > Ap f a > b # foldl' :: (b > a > b) > b > Ap f a > b # foldr1 :: (a > a > a) > Ap f a > a # foldl1 :: (a > a > a) > Ap f a > a # elem :: Eq a => a > Ap f a > Bool # maximum :: Ord a => Ap f a > a #  
Foldable f => Foldable (Alt f)  Since: base4.12.0.0 
Defined in Data.Foldable fold :: Monoid m => Alt f m > m # foldMap :: Monoid m => (a > m) > Alt f a > m # foldMap' :: Monoid m => (a > m) > Alt f a > m # foldr :: (a > b > b) > b > Alt f a > b # foldr' :: (a > b > b) > b > Alt f a > b # foldl :: (b > a > b) > b > Alt f a > b # foldl' :: (b > a > b) > b > Alt f a > b # foldr1 :: (a > a > a) > Alt f a > a # foldl1 :: (a > a > a) > Alt f a > a # elem :: Eq a => a > Alt f a > Bool # maximum :: Ord a => Alt f a > a # minimum :: Ord a => Alt f a > a #  
Foldable f => Foldable (Rec1 f)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => Rec1 f m > m # foldMap :: Monoid m => (a > m) > Rec1 f a > m # foldMap' :: Monoid m => (a > m) > Rec1 f a > m # foldr :: (a > b > b) > b > Rec1 f a > b # foldr' :: (a > b > b) > b > Rec1 f a > b # foldl :: (b > a > b) > b > Rec1 f a > b # foldl' :: (b > a > b) > b > Rec1 f a > b # foldr1 :: (a > a > a) > Rec1 f a > a # foldl1 :: (a > a > a) > Rec1 f a > a # elem :: Eq a => a > Rec1 f a > Bool # maximum :: Ord a => Rec1 f a > a # minimum :: Ord a => Rec1 f a > a #  
(Foldable f, Foldable g) => Foldable (f :*: g)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => (f :*: g) m > m # foldMap :: Monoid m => (a > m) > (f :*: g) a > m # foldMap' :: Monoid m => (a > m) > (f :*: g) a > m # foldr :: (a > b > b) > b > (f :*: g) a > b # foldr' :: (a > b > b) > b > (f :*: g) a > b # foldl :: (b > a > b) > b > (f :*: g) a > b # foldl' :: (b > a > b) > b > (f :*: g) a > b # foldr1 :: (a > a > a) > (f :*: g) a > a # foldl1 :: (a > a > a) > (f :*: g) a > a # toList :: (f :*: g) a > [a] # length :: (f :*: g) a > Int # elem :: Eq a => a > (f :*: g) a > Bool # maximum :: Ord a => (f :*: g) a > a # minimum :: Ord a => (f :*: g) a > a #  
(Foldable f, Foldable g) => Foldable (f :+: g)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => (f :+: g) m > m # foldMap :: Monoid m => (a > m) > (f :+: g) a > m # foldMap' :: Monoid m => (a > m) > (f :+: g) a > m # foldr :: (a > b > b) > b > (f :+: g) a > b # foldr' :: (a > b > b) > b > (f :+: g) a > b # foldl :: (b > a > b) > b > (f :+: g) a > b # foldl' :: (b > a > b) > b > (f :+: g) a > b # foldr1 :: (a > a > a) > (f :+: g) a > a # foldl1 :: (a > a > a) > (f :+: g) a > a # toList :: (f :+: g) a > [a] # length :: (f :+: g) a > Int # elem :: Eq a => a > (f :+: g) a > Bool # maximum :: Ord a => (f :+: g) a > a # minimum :: Ord a => (f :+: g) a > a #  
Foldable (K1 i c :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => K1 i c m > m # foldMap :: Monoid m => (a > m) > K1 i c a > m # foldMap' :: Monoid m => (a > m) > K1 i c a > m # foldr :: (a > b > b) > b > K1 i c a > b # foldr' :: (a > b > b) > b > K1 i c a > b # foldl :: (b > a > b) > b > K1 i c a > b # foldl' :: (b > a > b) > b > K1 i c a > b # foldr1 :: (a > a > a) > K1 i c a > a # foldl1 :: (a > a > a) > K1 i c a > a # elem :: Eq a => a > K1 i c a > Bool # maximum :: Ord a => K1 i c a > a # minimum :: Ord a => K1 i c a > a #  
(Foldable f, Foldable g) => Foldable (f :.: g)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => (f :.: g) m > m # foldMap :: Monoid m => (a > m) > (f :.: g) a > m # foldMap' :: Monoid m => (a > m) > (f :.: g) a > m # foldr :: (a > b > b) > b > (f :.: g) a > b # foldr' :: (a > b > b) > b > (f :.: g) a > b # foldl :: (b > a > b) > b > (f :.: g) a > b # foldl' :: (b > a > b) > b > (f :.: g) a > b # foldr1 :: (a > a > a) > (f :.: g) a > a # foldl1 :: (a > a > a) > (f :.: g) a > a # toList :: (f :.: g) a > [a] # length :: (f :.: g) a > Int # elem :: Eq a => a > (f :.: g) a > Bool # maximum :: Ord a => (f :.: g) a > a # minimum :: Ord a => (f :.: g) a > a #  
Foldable f => Foldable (M1 i c f)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => M1 i c f m > m # foldMap :: Monoid m => (a > m) > M1 i c f a > m # foldMap' :: Monoid m => (a > m) > M1 i c f a > m # foldr :: (a > b > b) > b > M1 i c f a > b # foldr' :: (a > b > b) > b > M1 i c f a > b # foldl :: (b > a > b) > b > M1 i c f a > b # foldl' :: (b > a > b) > b > M1 i c f a > b # foldr1 :: (a > a > a) > M1 i c f a > a # foldl1 :: (a > a > a) > M1 i c f a > a # elem :: Eq a => a > M1 i c f a > Bool # maximum :: Ord a => M1 i c f a > a # minimum :: Ord a => M1 i c f a > a # 
maximumBy :: Foldable t => (a > a > Ordering) > t a > a #
The largest element of a nonempty structure with respect to the given comparison function.
Examples
Basic usage:
>>>
maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
WARNING: This function is partial for possiblyempty structures like lists.
minimumBy :: Foldable t => (a > a > Ordering) > t a > a #
The least element of a nonempty structure with respect to the given comparison function.
Examples
Basic usage:
>>>
minimumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"!"
WARNING: This function is partial for possiblyempty structures like lists.
concat :: Foldable t => t [a] > [a] #
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]
and :: Foldable t => t Bool > 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 *
or :: Foldable t => t Bool > Bool #
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 *
any :: Foldable t => (a > Bool) > t a > 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 *
all :: Foldable t => (a > Bool) > t a > Bool #
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 *
notElem :: (Foldable t, Eq a) => a > t a > Bool infix 4 #
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 *
concatMap :: Foldable t => (a > [b]) > t a > [b] #
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]
foldrM :: (Foldable t, Monad m) => (a > b > m b) > b > t a > m b #
Righttoleft monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, c, ..., x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldrM f z t = do yy < f y z xx < f x yy ... bb < f b cc aa < f a bb return aa  Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a > m b
and f2 :: b > m c
,
their Kleisli composition (f1 >=> f2) :: a > m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldrM
is that it amounts to an application
to z
of a Kleisli composition:
foldrM f z t = f y >=> f x >=> ... >=> f b >=> f a $ z
The monadic effects of foldrM
are sequenced from right to left, and e.g.
folds of infinite lists will diverge.
If at some step the bind operator (
shortcircuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from a tail of the
element sequence. If you want to evaluate the monadic effects in
lefttoright order, or perhaps be able to shortcircuit after an initial
sequence of elements, you'll need to use foldlM
instead.
If the monadic effects don't shortcircuit, the outermost application of
f
is to the leftmost element a
, so that, ignoring effects, the result
looks like a right fold:
a `f` (b `f` (c `f` (... (x `f` (y `f` z))))).
Examples
Basic usage:
>>>
let f i acc = do { print i ; return $ i : acc }
>>>
foldrM f [] [0..3]
3 2 1 0 [0,1,2,3]
foldlM :: (Foldable t, Monad m) => (b > a > m b) > b > t a > m b #
Lefttoright monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, ..., w, x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldlM f z t = do aa < f z a bb < f aa b ... xx < f ww x yy < f xx y return yy  Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a > m b
and f2 :: b > m c
,
their Kleisli composition (f1 >=> f2) :: a > m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldlM
is that it amounts to an application
to z
of a Kleisli composition:
foldlM f z t = flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ z
The monadic effects of foldlM
are sequenced from left to right.
If at some step the bind operator (
shortcircuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from an initial
segment of the element sequence. If you want to evaluate the monadic
effects in righttoleft order, or perhaps be able to shortcircuit after
processing a tail of the sequence of elements, you'll need to use foldrM
instead.
If the monadic effects don't shortcircuit, the outermost application of
f
is to the rightmost element y
, so that, ignoring effects, the result
looks like a left fold:
((((z `f` a) `f` b) ... `f` w) `f` x) `f` y
Examples
Basic usage:
>>>
let f a e = do { print e ; return $ e : a }
>>>
foldlM f [] [0..3]
0 1 2 3 [3,2,1,0]
traverse_ :: (Foldable t, Applicative f) => (a > f b) > t a > f () #
Map each element of a structure to an Applicative
action, evaluate these
actions from left to right, and ignore the results. For a version that
doesn't ignore the results see traverse
.
traverse_
is just like mapM_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
traverse_ print ["Hello", "world", "!"]
"Hello" "world" "!"
for_ :: (Foldable t, Applicative f) => t a > (a > f b) > f () #
for_
is traverse_
with its arguments flipped. For a version
that doesn't ignore the results see for
. This
is forM_
generalised to Applicative
actions.
for_
is just like forM_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
for_ [1..4] print
1 2 3 4
sequenceA_ :: (Foldable t, Applicative f) => t (f a) > f () #
Evaluate each action in the structure from left to right, and
ignore the results. For a version that doesn't ignore the results
see sequenceA
.
sequenceA_
is just like sequence_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
sequenceA_ [print "Hello", print "world", print "!"]
"Hello" "world" "!"
sequence_ :: (Foldable t, Monad m) => t (m a) > 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.
asum :: (Foldable t, Alternative f) => t (f a) > f a #
The sum of a collection of actions using (<>)
, generalizing concat
.
asum
is just like msum
, but generalised to Alternative
.
Examples
Basic usage:
>>>
asum [Just "Hello", Nothing, Just "World"]
Just "Hello"
The Prelude
A fixedprecision integer type with at least the range [2^29 .. 2^291]
.
The exact range for a given implementation can be determined by using
minBound
and maxBound
from the Bounded
class.
Instances
Arbitrary precision integers. In contrast with fixedsize integral types
such as Int
, the Integer
type represents the entire infinite range of
integers.
Integers are stored in a kind of signmagnitude 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
Instances
Doubleprecision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE doubleprecision type.
Instances
Singleprecision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE singleprecision type.
Instances
Data Float  Since: base4.0.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Float > c Float # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c Float # dataTypeOf :: Float > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c Float) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c Float) # gmapT :: (forall b. Data b => b > b) > Float > Float # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Float > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > Float > r # gmapQ :: (forall d. Data d => d > u) > Float > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Float > u # 