Copyright | (c) The University of Glasgow 1992-2002 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | cvs-ghc@haskell.org |
Stability | internal |
Portability | non-portable (GHC extensions) |
Safe Haskell | Unsafe |
Language | Haskell2010 |
Basic data types and classes.
Synopsis
- augment :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a] -> [a]
- (++) :: [a] -> [a] -> [a]
- build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
- foldr :: (a -> b -> b) -> b -> [a] -> b
- eqString :: String -> String -> Bool
- bindIO :: IO a -> (a -> IO b) -> IO b
- returnIO :: a -> IO a
- otherwise :: Bool
- assert :: Bool -> a -> a
- thenIO :: IO a -> IO b -> IO b
- breakpoint :: a -> a
- breakpointCond :: Bool -> a -> a
- map :: (a -> b) -> [a] -> [b]
- ($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
- join :: Monad m => m (m a) -> m a
- class Applicative m => Monad m where
- class Functor f where
- class Functor f => Applicative f where
- class Semigroup a where
- class Semigroup a => Monoid a where
- data Opaque = forall a. O a
- type String = [Char]
- data NonEmpty a = a :| [a]
- class (Alternative m, Monad m) => MonadPlus m where
- class Applicative f => Alternative f where
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- when :: Applicative f => Bool -> f () -> f ()
- sequence :: Monad m => [m a] -> m [a]
- mapM :: Monad m => (a -> m b) -> [a] -> m [b]
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- ap :: Monad m => m (a -> b) -> m a -> m b
- mapFB :: (elt -> lst -> lst) -> (a -> elt) -> a -> lst -> lst
- unsafeChr :: Int -> Char
- ord :: Char -> Int
- minInt :: Int
- maxInt :: Int
- id :: a -> a
- const :: a -> b -> a
- (.) :: (b -> c) -> (a -> b) -> a -> c
- flip :: (a -> b -> c) -> b -> a -> c
- ($!) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
- until :: (a -> Bool) -> (a -> a) -> a -> a
- asTypeOf :: a -> a -> a
- unIO :: IO a -> State# RealWorld -> (# State# RealWorld, a #)
- getTag :: a -> Int#
- quotInt :: Int -> Int -> Int
- remInt :: Int -> Int -> Int
- divInt :: Int -> Int -> Int
- modInt :: Int -> Int -> Int
- quotRemInt :: Int -> Int -> (Int, Int)
- divModInt :: Int -> Int -> (Int, Int)
- divModInt# :: Int# -> Int# -> (# Int#, Int# #)
- shiftL# :: Word# -> Int# -> Word#
- shiftRL# :: Word# -> Int# -> Word#
- iShiftL# :: Int# -> Int# -> Int#
- iShiftRA# :: Int# -> Int# -> Int#
- iShiftRL# :: Int# -> Int# -> Int#
- module GHC.Classes
- module GHC.CString
- module GHC.Magic
- module GHC.Types
- module GHC.Prim
- module GHC.Err
- module GHC.Maybe
Documentation
(++) :: [a] -> [a] -> [a] infixr 5 #
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.
foldr :: (a -> b -> b) -> b -> [a] -> b #
foldr
, 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)...)
eqString :: String -> String -> Bool #
This String
equality predicate is used when desugaring
pattern-matches against strings.
If the first argument evaluates to True
, then the result is the
second argument. Otherwise an AssertionFailed
exception
is raised, containing a String
with the source file and line number of the
call to assert
.
Assertions can normally be turned on or off with a compiler flag
(for GHC, assertions are normally on unless optimisation is turned on
with -O
or the -fignore-asserts
option is given). When assertions are turned off, the first
argument to assert
is ignored, and the second argument is
returned as the result.
breakpoint :: a -> a #
breakpointCond :: Bool -> a -> a #
map :: (a -> b) -> [a] -> [b] #
O(n). 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]
($) :: forall r 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, 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
,
or map
($
0) xs
.zipWith
($
) fs xs
Note that (
is levity-polymorphic in its result type, so that
$
)foo
where $
Truefoo :: Bool -> Int#
is well-typed.
join :: Monad m => m (m a) -> m a #
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.
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
class Applicative m => Monad m where #
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:
- Left identity
return
a>>=
k = k a- Right identity
m
>>=
return
= m- Associativity
m
>>=
(\x -> k x>>=
h) = (m>>=
k)>>=
h
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.
(>>=) :: forall a b. m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: forall a b. m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
Instances
Monad [] # | Since: base-2.1 |
Monad Maybe # | Since: base-2.1 |
Monad IO # | Since: base-2.1 |
Monad Par1 # | Since: base-4.9.0.0 |
Monad NonEmpty # | Since: base-4.9.0.0 |
Monad NoIO # | Since: base-4.4.0.0 |
Monad ReadP # | Since: base-2.1 |
Monad ReadPrec # | Since: base-2.1 |
Monad Down # | Since: base-4.11.0.0 |
Monad Product # | Since: base-4.8.0.0 |
Monad Sum # | Since: base-4.8.0.0 |
Monad Dual # | Since: base-4.8.0.0 |
Monad Last # | Since: base-4.8.0.0 |
Monad First # | Since: base-4.8.0.0 |
Monad STM # | Since: base-4.3.0.0 |
Monad Identity # | Since: base-4.8.0.0 |
Monad Option # | Since: base-4.9.0.0 |
Monad Last # | Since: base-4.9.0.0 |
Monad First # | Since: base-4.9.0.0 |
Monad Max # | Since: base-4.9.0.0 |
Monad Min # | Since: base-4.9.0.0 |
Monad Complex # | Since: base-4.9.0.0 |
Monad (Either e) # | Since: base-4.4.0.0 |
Monad (U1 :: Type -> Type) # | Since: base-4.9.0.0 |
Monoid a => Monad ((,) a) # | Since: base-4.9.0.0 |
Monad (ST s) # | Since: base-2.1 |
Monad (Proxy :: Type -> Type) # | Since: base-4.7.0.0 |
ArrowApply a => Monad (ArrowMonad a) # | Since: base-2.1 |
Defined in Control.Arrow (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # | |
Monad m => Monad (WrappedMonad m) # | Since: base-4.7.0.0 |
Defined in Control.Applicative (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
Monad (ST s) # | Since: base-2.1 |
Monad f => Monad (Rec1 f) # | Since: base-4.9.0.0 |
Monad f => Monad (Alt f) # | Since: base-4.8.0.0 |
Monad f => Monad (Ap f) # | Since: base-4.12.0.0 |
Monad ((->) r :: Type -> Type) # | Since: base-2.1 |
(Monad f, Monad g) => Monad (f :*: g) # | Since: base-4.9.0.0 |
(Monad f, Monad g) => Monad (Product f g) # | Since: base-4.9.0.0 |
Monad f => Monad (M1 i c f) # | Since: base-4.9.0.0 |
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.
Instances
Functor [] # | Since: base-2.1 |
Functor Maybe # | Since: base-2.1 |
Functor IO # | Since: base-2.1 |
Functor Par1 # | Since: base-4.9.0.0 |
Functor NonEmpty # | Since: base-4.9.0.0 |
Functor NoIO # | Since: base-4.8.0.0 |
Functor ReadP # | Since: base-2.1 |
Functor ReadPrec # | Since: base-2.1 |
Functor Down # | Since: base-4.11.0.0 |
Functor Product # | Since: base-4.8.0.0 |
Functor Sum # | Since: base-4.8.0.0 |
Functor Dual # | Since: base-4.8.0.0 |
Functor Last # | Since: base-4.8.0.0 |
Functor First # | Since: base-4.8.0.0 |
Functor STM # | Since: base-4.3.0.0 |
Functor Handler # | Since: base-4.6.0.0 |
Functor Identity # | Since: base-4.8.0.0 |
Functor ZipList # | Since: base-2.1 |
Functor ArgDescr # | Since: base-4.6.0.0 |
Functor OptDescr # | Since: base-4.6.0.0 |
Functor ArgOrder # | Since: base-4.6.0.0 |
Functor Option # | Since: base-4.9.0.0 |
Functor Last # | Since: base-4.9.0.0 |
Functor First # | Since: base-4.9.0.0 |
Functor Max # | Since: base-4.9.0.0 |
Functor Min # | Since: base-4.9.0.0 |
Functor Complex # | Since: base-4.9.0.0 |
Functor (Either a) # | Since: base-3.0 |
Functor (V1 :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (U1 :: Type -> Type) # | Since: base-4.9.0.0 |
Functor ((,) a) # | Since: base-2.1 |
Functor (ST s) # | Since: base-2.1 |
Functor (Array i) # | Since: base-2.1 |
Functor (Proxy :: Type -> Type) # | Since: base-4.7.0.0 |
Arrow a => Functor (ArrowMonad a) # | Since: base-4.6.0.0 |
Defined in Control.Arrow fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Monad m => Functor (WrappedMonad m) # | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a # | |
Functor (ST s) # | Since: base-2.1 |
Functor (Arg a) # | Since: base-4.9.0.0 |
Functor f => Functor (Rec1 f) # | Since: base-4.9.0.0 |
Functor (URec Char :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (URec Double :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (URec Float :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (URec Int :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (URec Word :: Type -> Type) # | Since: base-4.9.0.0 |
Functor (URec (Ptr ()) :: Type -> Type) # | Since: base-4.9.0.0 |
Functor f => Functor (Alt f) # | Since: base-4.8.0.0 |
Functor f => Functor (Ap f) # | Since: base-4.12.0.0 |
Functor (Const m :: Type -> Type) # | Since: base-2.1 |
Arrow a => Functor (WrappedArrow a b) # | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Functor ((->) r :: Type -> Type) # | Since: base-2.1 |
Functor (K1 i c :: Type -> Type) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (f :+: g) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (f :*: g) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (Sum f g) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (Product f g) # | Since: base-4.9.0.0 |
Functor f => Functor (M1 i c f) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (f :.: g) # | Since: base-4.9.0.0 |
(Functor f, Functor g) => Functor (Compose f g) # | Since: base-4.9.0.0 |
class Functor f => Applicative f where #
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:
- Identity
pure
id
<*>
v = v- Composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- Homomorphism
pure
f<*>
pure
x =pure
(f x)- Interchange
u
<*>
pure
y =pure
($
y)<*>
u
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).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
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 <*>
.
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
Applicative [] # | Since: base-2.1 |
Applicative Maybe # | Since: base-2.1 |
Applicative IO # | Since: base-2.1 |
Applicative Par1 # | Since: base-4.9.0.0 |
Applicative NonEmpty # | Since: base-4.9.0.0 |
Applicative NoIO # | Since: base-4.8.0.0 |
Applicative ReadP # | Since: base-4.6.0.0 |
Applicative ReadPrec # | Since: base-4.6.0.0 |
Applicative Down # | Since: base-4.11.0.0 |
Applicative Product # | Since: base-4.8.0.0 |
Applicative Sum # | Since: base-4.8.0.0 |
Applicative Dual # | Since: base-4.8.0.0 |
Applicative Last # | Since: base-4.8.0.0 |
Applicative First # | Since: base-4.8.0.0 |
Applicative STM # | Since: base-4.8.0.0 |
Applicative Identity # | Since: base-4.8.0.0 |
Applicative ZipList # | f <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN) where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..] = ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..]) = ZipList {getZipList = ["a5","b6b6","c7c7c7"]} Since: base-2.1 |
Applicative Option # | Since: base-4.9.0.0 |
Applicative Last # | Since: base-4.9.0.0 |
Applicative First # | Since: base-4.9.0.0 |
Applicative Max # | Since: base-4.9.0.0 |
Applicative Min # | Since: base-4.9.0.0 |
Applicative Complex # | Since: base-4.9.0.0 |
Applicative (Either e) # | Since: base-3.0 |
Applicative (U1 :: Type -> Type) # | Since: base-4.9.0.0 |
Monoid a => Applicative ((,) a) # | For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base-2.1 |
Applicative (ST s) # | Since: base-4.4.0.0 |
Applicative (Proxy :: Type -> Type) # | Since: base-4.7.0.0 |
Arrow a => Applicative (ArrowMonad a) # | Since: base-4.6.0.0 |
Defined in Control.Arrow pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Monad m => Applicative (WrappedMonad m) # | Since: base-2.1 |
Defined in Control.Applicative pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
Applicative (ST s) # | Since: base-2.1 |
Applicative f => Applicative (Rec1 f) # | Since: base-4.9.0.0 |
Applicative f => Applicative (Alt f) # | Since: base-4.8.0.0 |
Applicative f => Applicative (Ap f) # | Since: base-4.12.0.0 |
Monoid m => Applicative (Const m :: Type -> Type) # | Since: base-2.0.1 |
Arrow a => Applicative (WrappedArrow a b) # | Since: base-2.1 |
Defined in Control.Applicative pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Applicative ((->) a :: Type -> Type) # | Since: base-2.1 |
Monoid c => Applicative (K1 i c :: Type -> Type) # | Since: base-4.12.0.0 |
(Applicative f, Applicative g) => Applicative (f :*: g) # | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Product f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
Applicative f => Applicative (M1 i c f) # | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (f :.: g) # | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Compose f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose |
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
Since: base-4.9.0.0
(<>) :: a -> a -> a infixr 6 #
An associative operation.
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
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 O(1) by
picking stimes =
or stimesIdempotent
stimes =
respectively.stimesIdempotentMonoid
Instances
Semigroup Ordering # | Since: base-4.9.0.0 |
Semigroup () # | Since: base-4.9.0.0 |
Semigroup Any # | Since: base-4.9.0.0 |
Semigroup All # | Since: base-4.9.0.0 |
Semigroup Lifetime # | Since: base-4.10.0.0 |
Semigroup Event # | Since: base-4.10.0.0 |
Semigroup Void # | Since: base-4.9.0.0 |
Semigroup [a] # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Maybe a) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (IO a) # | Since: base-4.10.0.0 |
Semigroup p => Semigroup (Par1 p) # | Since: base-4.12.0.0 |
Semigroup (NonEmpty a) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Down a) # | Since: base-4.11.0.0 |
Num a => Semigroup (Product a) # | Since: base-4.9.0.0 |
Num a => Semigroup (Sum a) # | Since: base-4.9.0.0 |
Semigroup (Endo a) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Dual a) # | Since: base-4.9.0.0 |
Semigroup (Last a) # | Since: base-4.9.0.0 |
Semigroup (First a) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Identity a) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Option a) # | Since: base-4.9.0.0 |
Monoid m => Semigroup (WrappedMonoid m) # | Since: base-4.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 (Last a) # | Since: base-4.9.0.0 |
Semigroup (First a) # | Since: base-4.9.0.0 |
Ord a => Semigroup (Max a) # | Since: base-4.9.0.0 |
Ord a => Semigroup (Min a) # | Since: base-4.9.0.0 |
Semigroup (Equivalence a) # | |
Defined in Data.Functor.Contravariant (<>) :: Equivalence a -> Equivalence a -> Equivalence a # sconcat :: NonEmpty (Equivalence a) -> Equivalence a # stimes :: Integral b => b -> Equivalence a -> Equivalence a # | |
Semigroup (Comparison a) # | |
Defined in Data.Functor.Contravariant (<>) :: Comparison a -> Comparison a -> Comparison a # sconcat :: NonEmpty (Comparison a) -> Comparison a # stimes :: Integral b => b -> Comparison a -> Comparison a # | |
Semigroup (Predicate a) # | |
Semigroup b => Semigroup (a -> b) # | Since: base-4.9.0.0 |
Semigroup (Either a b) # | Since: base-4.9.0.0 |
Semigroup (V1 p) # | Since: base-4.12.0.0 |
Semigroup (U1 p) # | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b) => Semigroup (a, b) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (ST s a) # | Since: base-4.11.0.0 |
Semigroup (Proxy s) # | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Op a b) # | |
Semigroup (f p) => Semigroup (Rec1 f p) # | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) # | Since: base-4.9.0.0 |
Alternative f => Semigroup (Alt f a) # | Since: base-4.9.0.0 |
(Applicative f, Semigroup a) => Semigroup (Ap f a) # | Since: base-4.12.0.0 |
Semigroup a => Semigroup (Const a b) # | Since: base-4.9.0.0 |
Semigroup c => Semigroup (K1 i c p) # | Since: base-4.12.0.0 |
(Semigroup (f p), Semigroup (g p)) => Semigroup ((f :*: g) p) # | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) # | Since: base-4.9.0.0 |
Semigroup (f p) => Semigroup (M1 i c f p) # | Since: base-4.12.0.0 |
Semigroup (f (g p)) => Semigroup ((f :.: g) p) # | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) # | Since: base-4.9.0.0 |
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
x
<>
mempty
= x- Left identity
mempty
<>
x = x- Associativity
x
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)- Concatenation
mconcat
=foldr
(<>
)mempty
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 newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= (<>
)
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.
Instances
Monoid Ordering # | Since: base-2.1 |
Monoid () # | Since: base-2.1 |
Monoid Any # | Since: base-2.1 |
Monoid All # | Since: base-2.1 |
Monoid Lifetime # |
Since: base-4.8.0.0 |
Monoid Event # | Since: base-4.4.0.0 |
Monoid [a] # | Since: base-2.1 |
Semigroup a => Monoid (Maybe a) # | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (IO a) # | Since: base-4.9.0.0 |
Monoid p => Monoid (Par1 p) # | Since: base-4.12.0.0 |
Monoid a => Monoid (Down a) # | Since: base-4.11.0.0 |
Num a => Monoid (Product a) # | Since: base-2.1 |
Num a => Monoid (Sum a) # | Since: base-2.1 |
Monoid (Endo a) # | Since: base-2.1 |
Monoid a => Monoid (Dual a) # | Since: base-2.1 |
Monoid (Last a) # | Since: base-2.1 |
Monoid (First a) # | Since: base-2.1 |
Monoid a => Monoid (Identity a) # | Since: base-4.9.0.0 |
Semigroup a => Monoid (Option a) # | Since: base-4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) # | Since: base-4.9.0.0 |
Defined in Data.Semigroup mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
(Ord a, Bounded a) => Monoid (Max a) # | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Min a) # | Since: base-4.9.0.0 |
Monoid (Equivalence a) # | |
Defined in Data.Functor.Contravariant mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
Monoid (Comparison a) # | |
Defined in Data.Functor.Contravariant mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
Monoid (Predicate a) # | |
Monoid b => Monoid (a -> b) # | Since: base-2.1 |
Monoid (U1 p) # | Since: base-4.12.0.0 |
(Monoid a, Monoid b) => Monoid (a, b) # | Since: base-2.1 |
Monoid a => Monoid (ST s a) # | Since: base-4.11.0.0 |
Monoid (Proxy s) # | Since: base-4.7.0.0 |
Monoid a => Monoid (Op a b) # | |
Monoid (f p) => Monoid (Rec1 f p) # | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) # | Since: base-2.1 |
Alternative f => Monoid (Alt f a) # | Since: base-4.8.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) # | Since: base-4.12.0.0 |
Monoid a => Monoid (Const a b) # | Since: base-4.9.0.0 |
Monoid c => Monoid (K1 i c p) # | Since: base-4.12.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) # | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) # | Since: base-2.1 |
Monoid (f p) => Monoid (M1 i c f p) # | Since: base-4.12.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) # | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) # | Since: base-2.1 |
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
a :| [a] infixr 5 |
Instances
Monad NonEmpty # | Since: base-4.9.0.0 |
Functor NonEmpty # | Since: base-4.9.0.0 |
MonadFix NonEmpty # | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
Applicative NonEmpty # | Since: base-4.9.0.0 |
Foldable NonEmpty # | Since: base-4.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 # | |
Traversable NonEmpty # | Since: base-4.9.0.0 |
MonadZip NonEmpty # | Since: base-4.9.0.0 |
Show1 NonEmpty # | Since: base-4.10.0.0 |
Read1 NonEmpty # | Since: base-4.10.0.0 |
Defined in Data.Functor.Classes | |
Ord1 NonEmpty # | Since: base-4.10.0.0 |
Defined in Data.Functor.Classes | |
Eq1 NonEmpty # | Since: base-4.10.0.0 |
IsList (NonEmpty a) # | Since: base-4.9.0.0 |
Eq a => Eq (NonEmpty a) # | Since: base-4.9.0.0 |
Data a => Data (NonEmpty a) # | Since: base-4.9.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonEmpty a -> c (NonEmpty a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonEmpty a) # toConstr :: NonEmpty a -> Constr # dataTypeOf :: NonEmpty a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonEmpty a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonEmpty a)) # gmapT :: (forall b. Data b => b -> b) -> NonEmpty a -> NonEmpty a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQ :: (forall d. Data d => d -> u) -> NonEmpty a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> NonEmpty a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # | |
Ord a => Ord (NonEmpty a) # | Since: base-4.9.0.0 |
Defined in GHC.Base compare :: NonEmpty a -> NonEmpty a -> Ordering Source # (<) :: NonEmpty a -> NonEmpty a -> Bool Source # (<=) :: NonEmpty a -> NonEmpty a -> Bool Source # (>) :: NonEmpty a -> NonEmpty a -> Bool Source # (>=) :: NonEmpty a -> NonEmpty a -> Bool Source # | |
Read a => Read (NonEmpty a) # | Since: base-4.11.0.0 |
Show a => Show (NonEmpty a) # | Since: base-4.11.0.0 |
Generic (NonEmpty a) # | Since: base-4.6.0.0 |
Semigroup (NonEmpty a) # | Since: base-4.9.0.0 |
Generic1 NonEmpty # | Since: base-4.6.0.0 |
type Rep (NonEmpty a) # | |
Defined in GHC.Generics type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) | |
type Item (NonEmpty a) # | |
type Rep1 NonEmpty # | |
Defined in GHC.Generics type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 []))) |
class (Alternative m, Monad m) => MonadPlus m where #
Monads that also support choice and failure.
Nothing
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
MonadPlus [] # | Since: base-2.1 |
MonadPlus Maybe # | Since: base-2.1 |
MonadPlus IO # | Since: base-4.9.0.0 |
MonadPlus ReadP # | Since: base-2.1 |
MonadPlus ReadPrec # | Since: base-2.1 |
MonadPlus STM # | Since: base-4.3.0.0 |
MonadPlus Option # | Since: base-4.9.0.0 |
MonadPlus (U1 :: Type -> Type) # | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) # | Since: base-4.9.0.0 |
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) # | Since: base-4.6.0.0 |
Defined in Control.Arrow mzero :: ArrowMonad a a0 # mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # | |
MonadPlus f => MonadPlus (Rec1 f) # | Since: base-4.9.0.0 |
MonadPlus f => MonadPlus (Alt f) # | Since: base-4.8.0.0 |
MonadPlus f => MonadPlus (Ap f) # | Since: base-4.12.0.0 |
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) # | Since: base-4.9.0.0 |
(MonadPlus f, MonadPlus g) => MonadPlus (Product f g) # | Since: base-4.9.0.0 |
MonadPlus f => MonadPlus (M1 i c f) # | Since: base-4.9.0.0 |
class Applicative f => Alternative f where #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
liftA :: Applicative f => (a -> b) -> f a -> f b #
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
when :: Applicative f => Bool -> f () -> f () #
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.
sequence :: Monad m => [m a] -> m [a] #
Evaluate each action in the sequence from left to right, and collect the results.
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. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
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 #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
const x
is a unary function which evaluates to x
for all inputs.
>>>
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"
($!) :: forall r a (b :: TYPE r). (a -> b) -> a -> b infixr 0 #
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.
until :: (a -> Bool) -> (a -> a) -> a -> a #
yields the result of applying until
p ff
until p
holds.
Returns the tag of a constructor application; this function is used by the deriving code for Eq, Ord and Enum.
shiftL# :: Word# -> Int# -> Word# #
Shift the argument left by the specified number of bits (which must be non-negative).
shiftRL# :: Word# -> Int# -> Word# #
Shift the argument right by the specified number of bits (which must be non-negative). The RL means "right, logical" (as opposed to RA for arithmetic) (although an arithmetic right shift wouldn't make sense for Word#)
iShiftL# :: Int# -> Int# -> Int# #
Shift the argument left by the specified number of bits (which must be non-negative).
iShiftRA# :: Int# -> Int# -> Int# #
Shift the argument right (signed) by the specified number of bits (which must be non-negative). The RA means "right, arithmetic" (as opposed to RL for logical)
iShiftRL# :: Int# -> Int# -> Int# #
Shift the argument right (unsigned) by the specified number of bits (which must be non-negative). The RL means "right, logical" (as opposed to RA for arithmetic)
module GHC.Classes
module GHC.CString
module GHC.Magic
module GHC.Types
module GHC.Prim
module GHC.Err
module GHC.Maybe