On this page
GHC.Base
| 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 |
Description
Basic data types and classes.
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
Constructors
| a :| [a] infixr 5 |
Instances
| MonadFix NonEmpty Source | Since: base-4.9.0.0 |
|
Defined in Control.Monad.Fix |
|
| MonadZip NonEmpty Source | Since: base-4.9.0.0 |
| Foldable NonEmpty Source | Since: base-4.9.0.0 |
|
Defined in Data.Foldable Methodsfold :: Monoid m => NonEmpty m -> m Source foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m Source foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m Source foldr :: (a -> b -> b) -> b -> NonEmpty a -> b Source foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b Source foldl :: (b -> a -> b) -> b -> NonEmpty a -> b Source foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b Source foldr1 :: (a -> a -> a) -> NonEmpty a -> a Source foldl1 :: (a -> a -> a) -> NonEmpty a -> a Source toList :: NonEmpty a -> [a] Source null :: NonEmpty a -> Bool Source length :: NonEmpty a -> Int Source elem :: Eq a => a -> NonEmpty a -> Bool Source maximum :: Ord a => NonEmpty a -> a Source minimum :: Ord a => NonEmpty a -> a Source |
|
| Eq1 NonEmpty Source | Since: base-4.10.0.0 |
| Ord1 NonEmpty Source | Since: base-4.10.0.0 |
|
Defined in Data.Functor.Classes |
|
| Read1 NonEmpty Source | Since: base-4.10.0.0 |
|
Defined in Data.Functor.Classes MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (NonEmpty a) Source liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [NonEmpty a] Source liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmpty a) Source liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [NonEmpty a] Source |
|
| Show1 NonEmpty Source | Since: base-4.10.0.0 |
| Traversable NonEmpty Source | Since: base-4.9.0.0 |
|
Defined in Data.Traversable |
|
| Applicative NonEmpty Source | Since: base-4.9.0.0 |
|
Defined in GHC.Base |
|
| Functor NonEmpty Source | Since: base-4.9.0.0 |
| Monad NonEmpty Source | Since: base-4.9.0.0 |
| Generic1 NonEmpty Source | |
| Data a => Data (NonEmpty a) Source | Since: base-4.9.0.0 |
|
Defined in Data.Data Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonEmpty a -> c (NonEmpty a) Source gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonEmpty a) Source toConstr :: NonEmpty a -> Constr Source dataTypeOf :: NonEmpty a -> DataType Source dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonEmpty a)) Source dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonEmpty a)) Source gmapT :: (forall b. Data b => b -> b) -> NonEmpty a -> NonEmpty a Source gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r Source gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r Source gmapQ :: (forall d. Data d => d -> u) -> NonEmpty a -> [u] Source gmapQi :: Int -> (forall d. Data d => d -> u) -> NonEmpty a -> u Source gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) Source gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) Source gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) Source |
|
| Semigroup (NonEmpty a) Source | Since: base-4.9.0.0 |
| Generic (NonEmpty a) Source | |
| IsList (NonEmpty a) Source | Since: base-4.9.0.0 |
| Read a => Read (NonEmpty a) Source | Since: base-4.11.0.0 |
| Show a => Show (NonEmpty a) Source | Since: base-4.11.0.0 |
| Eq a => Eq (NonEmpty a) Source | Since: base-4.9.0.0 |
| Ord a => Ord (NonEmpty a) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Base Methodscompare :: 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 |
|
| type Rep1 NonEmpty Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics
type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))
|
|
| type Rep (NonEmpty a) Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics
type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) '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) Source | |
|
Defined in GHC.IsList |
|
class Applicative m => Monad m where Source
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.
Minimal complete definition
Methods
(>>=) :: forall a b. m a -> (a -> m b) -> m b infixl 1 Source
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as >>= bs' can be understood as the do expression
do a <- as
bs a
(>>) :: forall a b. m a -> m b -> m b infixl 1 Source
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as >> bs' can be understood as the do expression
do as
bs
Inject a value into the monadic type.
Instances
| Monad Complex Source | Since: base-4.9.0.0 |
| Monad Identity Source | Since: base-4.8.0.0 |
| Monad First Source | Since: base-4.8.0.0 |
| Monad Last Source | Since: base-4.8.0.0 |
| Monad Down Source | Since: base-4.11.0.0 |
| Monad First Source | Since: base-4.9.0.0 |
| Monad Last Source | Since: base-4.9.0.0 |
| Monad Max Source | Since: base-4.9.0.0 |
| Monad Min Source | Since: base-4.9.0.0 |
| Monad Dual Source | Since: base-4.8.0.0 |
| Monad Product Source | Since: base-4.8.0.0 |
| Monad Sum Source | Since: base-4.8.0.0 |
| Monad STM Source | Since: base-4.3.0.0 |
| Monad NoIO Source | Since: base-4.4.0.0 |
| Monad Par1 Source | Since: base-4.9.0.0 |
| Monad ReadP Source | Since: base-2.1 |
| Monad ReadPrec Source | Since: base-2.1 |
| Monad IO Source | Since: base-2.1 |
| Monad NonEmpty Source | Since: base-4.9.0.0 |
| Monad Maybe Source | Since: base-2.1 |
| Monad Solo Source | Since: base-4.15 |
| Monad [] Source | Since: base-2.1 |
| Monad m => Monad (WrappedMonad m) Source | Since: base-4.7.0.0 |
|
Defined in Control.Applicative Methods(>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b Source (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source return :: a -> WrappedMonad m a Source |
|
| ArrowApply a => Monad (ArrowMonad a) Source | Since: base-2.1 |
|
Defined in Control.Arrow Methods(>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b Source (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source return :: a0 -> ArrowMonad a a0 Source |
|
| Monad (ST s) Source | Since: base-2.1 |
| Monad (Either e) Source | Since: base-4.4.0.0 |
| Monad (Proxy :: Type -> Type) Source | Since: base-4.7.0.0 |
| Monad (U1 :: Type -> Type) Source | Since: base-4.9.0.0 |
| Monad (ST s) Source | Since: base-2.1 |
| Monoid a => Monad ((,) a) Source | Since: base-4.9.0.0 |
| Monad m => Monad (Kleisli m a) Source | Since: base-4.14.0.0 |
| Monad f => Monad (Ap f) Source | Since: base-4.12.0.0 |
| Monad f => Monad (Alt f) Source | Since: base-4.8.0.0 |
| Monad f => Monad (Rec1 f) Source | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Monad ((,,) a b) Source | Since: base-4.14.0.0 |
| (Monad f, Monad g) => Monad (Product f g) Source | Since: base-4.9.0.0 |
| (Monad f, Monad g) => Monad (f :*: g) Source | Since: base-4.9.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) Source | Since: base-4.14.0.0 |
| Monad ((->) r) Source | Since: base-2.1 |
| Monad f => Monad (M1 i c f) Source | Since: base-4.9.0.0 |
class Functor f => Applicative f where Source
A functor with application, providing operations to
- embed pure expressions (
pure), and - sequence computations and combine their results (
<*>andliftA2).
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).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 Source
Sequential application.
A few functors support an implementation of <*> that is more efficient than the default one.
Example
Used in combination with (<$>), (<*>) can be used to build a record.
>>> data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>> produceFoo :: Applicative f => f Foo
>>> produceBar :: Applicative f => f Bar
>>> produceBaz :: Applicative f => f Baz
>>> mkState :: Applicative f => f MyState
>>> mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f c Source
Lift a binary function to actions.
Some functors support an implementation of liftA2 that is more efficient than the default one. In particular, if fmap is an expensive operation, it is likely better to use liftA2 than to fmap over the structure and then use <*>.
This became a typeclass method in 4.10.0.0. Prior to that, it was a function defined in terms of <*> and fmap.
Example
>>> liftA2 (,) (Just 3) (Just 5)
Just (3,5)
(*>) :: f a -> f b -> f b infixl 4 Source
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.
>>> Just 2 *> Just 3
Just 3
>>> Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>> import Data.Char
>>> import Text.ParserCombinators.ReadP
>>> let p = string "my name is " *> munch1 isAlpha <* eof
>>> readP_to_S p "my name is Simon"
[("Simon","")]
(<*) :: f a -> f b -> f a infixl 4 Source
Sequence actions, discarding the value of the second argument.
Instances
| Applicative ZipList Source | where Since: base-2.1 |
| Applicative Complex Source | Since: base-4.9.0.0 |
| Applicative Identity Source | Since: base-4.8.0.0 |
|
Defined in Data.Functor.Identity |
|
| Applicative First Source | Since: base-4.8.0.0 |
| Applicative Last Source | Since: base-4.8.0.0 |
| Applicative Down Source | Since: base-4.11.0.0 |
| Applicative First Source | Since: base-4.9.0.0 |
| Applicative Last Source | Since: base-4.9.0.0 |
| Applicative Max Source | Since: base-4.9.0.0 |
| Applicative Min Source | Since: base-4.9.0.0 |
| Applicative Dual Source | Since: base-4.8.0.0 |
| Applicative Product Source | Since: base-4.8.0.0 |
|
Defined in Data.Semigroup.Internal |
|
| Applicative Sum Source | Since: base-4.8.0.0 |
| Applicative STM Source | Since: base-4.8.0.0 |
| Applicative NoIO Source | Since: base-4.8.0.0 |
| Applicative Par1 Source | Since: base-4.9.0.0 |
| Applicative ReadP Source | Since: base-4.6.0.0 |
| Applicative ReadPrec Source | Since: base-4.6.0.0 |
|
Defined in Text.ParserCombinators.ReadPrec |
|
| Applicative IO Source | Since: base-2.1 |
| Applicative NonEmpty Source | Since: base-4.9.0.0 |
|
Defined in GHC.Base |
|
| Applicative Maybe Source | Since: base-2.1 |
| Applicative Solo Source | Since: base-4.15 |
| Applicative [] Source | Since: base-2.1 |
| Monad m => Applicative (WrappedMonad m) Source | Since: base-2.1 |
|
Defined in Control.Applicative Methodspure :: a -> WrappedMonad m a Source (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c Source (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a Source |
|
| Arrow a => Applicative (ArrowMonad a) Source | Since: base-4.6.0.0 |
|
Defined in Control.Arrow Methodspure :: a0 -> ArrowMonad a a0 Source (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c Source (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 Source |
|
| Applicative (ST s) Source | Since: base-2.1 |
| Applicative (Either e) Source | Since: base-3.0 |
|
Defined in Data.Either |
|
| Applicative (Proxy :: Type -> Type) Source | Since: base-4.7.0.0 |
| Applicative (U1 :: Type -> Type) Source | Since: base-4.9.0.0 |
| Applicative (ST s) Source | Since: base-4.4.0.0 |
| Monoid a => Applicative ((,) a) Source | For tuples, the Since: base-2.1 |
| Arrow a => Applicative (WrappedArrow a b) Source | Since: base-2.1 |
|
Defined in Control.Applicative Methodspure :: a0 -> WrappedArrow a b a0 Source (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c Source (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 Source (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source |
|
| Applicative m => Applicative (Kleisli m a) Source | Since: base-4.14.0.0 |
|
Defined in Control.Arrow Methodspure :: a0 -> Kleisli m a a0 Source (<*>) :: Kleisli m a (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b Source liftA2 :: (a0 -> b -> c) -> Kleisli m a a0 -> Kleisli m a b -> Kleisli m a c Source (*>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b Source (<*) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a a0 Source |
|
| Monoid m => Applicative (Const m :: Type -> Type) Source | Since: base-2.0.1 |
| Applicative f => Applicative (Ap f) Source | Since: base-4.12.0.0 |
| Applicative f => Applicative (Alt f) Source | Since: base-4.8.0.0 |
| (Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f) Source | Since: base-4.17.0.0 |
|
Defined in GHC.Generics Methodspure :: a -> Generically1 f a Source (<*>) :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b Source liftA2 :: (a -> b -> c) -> Generically1 f a -> Generically1 f b -> Generically1 f c Source (*>) :: Generically1 f a -> Generically1 f b -> Generically1 f b Source (<*) :: Generically1 f a -> Generically1 f b -> Generically1 f a Source |
|
| Applicative f => Applicative (Rec1 f) Source | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Applicative ((,,) a b) Source | Since: base-4.14.0.0 |
|
Defined in GHC.Base |
|
| (Applicative f, Applicative g) => Applicative (Product f g) Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Product Methodspure :: a -> Product f g a Source (<*>) :: Product f g (a -> b) -> Product f g a -> Product f g b Source liftA2 :: (a -> b -> c) -> Product f g a -> Product f g b -> Product f g c Source (*>) :: Product f g a -> Product f g b -> Product f g b Source (<*) :: Product f g a -> Product f g b -> Product f g a Source |
|
| (Applicative f, Applicative g) => Applicative (f :*: g) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics |
|
| Monoid c => Applicative (K1 i c :: Type -> Type) Source | Since: base-4.12.0.0 |
| (Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) Source | Since: base-4.14.0.0 |
|
Defined in GHC.Base Methodspure :: a0 -> (a, b, c, a0) Source (<*>) :: (a, b, c, a0 -> b0) -> (a, b, c, a0) -> (a, b, c, b0) Source liftA2 :: (a0 -> b0 -> c0) -> (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, c0) Source (*>) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, b0) Source (<*) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, a0) Source |
|
| Applicative ((->) r) Source | Since: base-2.1 |
| (Applicative f, Applicative g) => Applicative (Compose f g) Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Compose Methodspure :: a -> Compose f g a Source (<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b Source liftA2 :: (a -> b -> c) -> Compose f g a -> Compose f g b -> Compose f g c Source (*>) :: Compose f g a -> Compose f g b -> Compose f g b Source (<*) :: Compose f g a -> Compose f g b -> Compose f g a Source |
|
| (Applicative f, Applicative g) => Applicative (f :.: g) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics |
|
| Applicative f => Applicative (M1 i c f) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics |
|
class Applicative f => Alternative f where Source
A monoid on applicative functors.
If defined, some and many should be the least solutions of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 Source
An associative binary operation
One or more.
Zero or more.
Instances
A type f is a Functor if it provides a function fmap which, given any types a and b lets you apply any function from (a -> b) to turn an f a into an f b, preserving the structure of f. Furthermore f needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap and the first law, so you need only check that the former condition holds. See https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or https://github.com/quchen/articles/blob/master/second_functor_law.md for an explanation.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b Source
fmap is used to apply a function of type (a -> b) to a value of type f a, where f is a functor, to produce a value of type f b. Note that for any type constructor with more than one parameter (e.g., Either), only the last type parameter can be modified with fmap (e.g., b in `Either a b`).
Some type constructors with two parameters or more have a Bifunctor instance that allows both the last and the penultimate parameters to be mapped over.
Examples
Convert from a Maybe Int to a Maybe String using show:
>>> fmap show Nothing
Nothing
>>> fmap show (Just 3)
Just "3"
Convert from an Either Int Int to an Either Int String using show:
>>> fmap show (Left 17)
Left 17
>>> fmap show (Right 17)
Right "17"
Double each element of a list:
>>> fmap (*2) [1,2,3]
[2,4,6]
Apply even to the second element of a pair:
>>> fmap even (2,2)
(2,True)
It may seem surprising that the function is only applied to the last element of the tuple compared to the list example above which applies it to every element in the list. To understand, remember that tuples are type constructors with multiple type parameters: a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over with fmap).
It explains why fmap can be used with tuples containing values of different types as in the following example:
>>> fmap even ("hello", 1.0, 4)
("hello",1.0,True)
(<$) :: a -> f b -> f a infixl 4 Source
Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version.
Instances
| Functor ZipList Source | Since: base-2.1 |
| Functor Handler Source | Since: base-4.6.0.0 |
| Functor Complex Source | Since: base-4.9.0.0 |
| Functor Identity Source | Since: base-4.8.0.0 |
| Functor First Source | Since: base-4.8.0.0 |
| Functor Last Source | Since: base-4.8.0.0 |
| Functor Down Source | Since: base-4.11.0.0 |
| Functor First Source | Since: base-4.9.0.0 |
| Functor Last Source | Since: base-4.9.0.0 |
| Functor Max Source | Since: base-4.9.0.0 |
| Functor Min Source | Since: base-4.9.0.0 |
| Functor Dual Source | Since: base-4.8.0.0 |
| Functor Product Source | Since: base-4.8.0.0 |
| Functor Sum Source | Since: base-4.8.0.0 |
| Functor STM Source | Since: base-4.3.0.0 |
| Functor NoIO Source | Since: base-4.8.0.0 |
| Functor Par1 Source | Since: base-4.9.0.0 |
| Functor ArgDescr Source | Since: base-4.7.0.0 |
| Functor ArgOrder Source | Since: base-4.7.0.0 |
| Functor OptDescr Source | Since: base-4.7.0.0 |
| Functor ReadP Source | Since: base-2.1 |
| Functor ReadPrec Source | Since: base-2.1 |
| Functor IO Source | Since: base-2.1 |
| Functor NonEmpty Source | Since: base-4.9.0.0 |
| Functor Maybe Source | Since: base-2.1 |
| Functor Solo Source | Since: base-4.15 |
| Functor [] Source | Since: base-2.1 |
| Monad m => Functor (WrappedMonad m) Source | Since: base-2.1 |
|
Defined in Control.Applicative Methodsfmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source (<$) :: a -> WrappedMonad m b -> WrappedMonad m a Source |
|
| Arrow a => Functor (ArrowMonad a) Source | Since: base-4.6.0.0 |
|
Defined in Control.Arrow Methodsfmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 Source |
|
| Functor (ST s) Source | Since: base-2.1 |
| Functor (Either a) Source | Since: base-3.0 |
| Functor (Proxy :: Type -> Type) Source | Since: base-4.7.0.0 |
| Functor (Arg a) Source | Since: base-4.9.0.0 |
| Functor (Array i) Source | Since: base-2.1 |
| Functor (U1 :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (V1 :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (ST s) Source | Since: base-2.1 |
| Functor ((,) a) Source | Since: base-2.1 |
| Arrow a => Functor (WrappedArrow a b) Source | Since: base-2.1 |
|
Defined in Control.Applicative Methodsfmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source |
|
| Functor m => Functor (Kleisli m a) Source | Since: base-4.14.0.0 |
| Functor (Const m :: Type -> Type) Source | Since: base-2.1 |
| Functor f => Functor (Ap f) Source | Since: base-4.12.0.0 |
| Functor f => Functor (Alt f) Source | Since: base-4.8.0.0 |
| (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f) Source | Since: base-4.17.0.0 |
|
Defined in GHC.Generics Methodsfmap :: (a -> b) -> Generically1 f a -> Generically1 f b Source (<$) :: a -> Generically1 f b -> Generically1 f a Source |
|
| Functor f => Functor (Rec1 f) Source | Since: base-4.9.0.0 |
| Functor (URec (Ptr ()) :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Char :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Double :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Float :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Int :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Word :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor ((,,) a b) Source | Since: base-4.14.0.0 |
| (Functor f, Functor g) => Functor (Product f g) Source | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Sum f g) Source | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :*: g) Source | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :+: g) Source | Since: base-4.9.0.0 |
| Functor (K1 i c :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor ((,,,) a b c) Source | Since: base-4.14.0.0 |
| Functor ((->) r) Source | Since: base-2.1 |
| (Functor f, Functor g) => Functor (Compose f g) Source | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :.: g) Source | Since: base-4.9.0.0 |
| Functor f => Functor (M1 i c f) Source | Since: base-4.9.0.0 |
class (Alternative m, Monad m) => MonadPlus m where Source
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero
v >> mzero = mzero
The default definition is
mzero = empty
mplus :: m a -> m a -> m a Source
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus STM Source | Since: base-4.3.0.0 |
| MonadPlus ReadP Source | Since: base-2.1 |
| MonadPlus ReadPrec Source | Since: base-2.1 |
| MonadPlus IO Source | Since: base-4.9.0.0 |
| MonadPlus Maybe Source | Since: base-2.1 |
| MonadPlus [] Source | Since: base-2.1 |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) Source | Since: base-4.6.0.0 |
|
Defined in Control.Arrow Methodsmzero :: ArrowMonad a a0 Source mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 Source |
|
| MonadPlus (Proxy :: Type -> Type) Source | Since: base-4.9.0.0 |
| MonadPlus (U1 :: Type -> Type) Source | Since: base-4.9.0.0 |
| MonadPlus m => MonadPlus (Kleisli m a) Source | Since: base-4.14.0.0 |
| MonadPlus f => MonadPlus (Ap f) Source | Since: base-4.12.0.0 |
| MonadPlus f => MonadPlus (Alt f) Source | Since: base-4.8.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) Source | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product f g) Source | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) Source | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (M1 i c f) Source | Since: base-4.9.0.0 |
A String is a list of characters. String constants in Haskell are values of type String.
See Data.List for operations on lists.
class Semigroup a => Monoid a where Source
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) <> z(Semigrouplaw)- 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 newtypes and make those instances of Monoid, e.g. Sum and Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Minimal complete definition
Methods
Identity of mappend
>>> "Hello world" <> mempty
"Hello world"
An associative operation
NOTE: This method is redundant and has the default implementation mappend = (<>) since base-4.11.0.0. Should it be implemented manually, since mappend is a synonym for (<>), it is expected that the two functions are defined the same way. In a future GHC release mappend will be removed from Monoid.
Fold a list using the monoid.
For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.
>>> mconcat ["Hello", " ", "Haskell", "!"]
"Hello Haskell!"
Instances
| Monoid ByteArray Source | Since: base-4.17.0.0 |
| Monoid All Source | Since: base-2.1 |
| Monoid Any Source | Since: base-2.1 |
| Monoid Event Source | Since: base-4.4.0.0 |
| Monoid Lifetime Source |
Since: base-4.8.0.0 |
| Monoid Ordering Source | Since: base-2.1 |
| Monoid () Source | Since: base-2.1 |
| FiniteBits a => Monoid (And a) Source | This constraint is arguably too strong. However, as some types (such as Since: base-4.16 |
| FiniteBits a => Monoid (Iff a) Source | This constraint is arguably too strong. However, as some types (such as Since: base-4.16 |
| Bits a => Monoid (Ior a) Source | Since: base-4.16 |
| Bits a => Monoid (Xor a) Source | Since: base-4.16 |
| Monoid (Comparison a) Source |
|
|
Defined in Data.Functor.Contravariant Methodsmempty :: Comparison a Source mappend :: Comparison a -> Comparison a -> Comparison a Source mconcat :: [Comparison a] -> Comparison a Source |
|
| Monoid (Equivalence a) Source |
|
|
Defined in Data.Functor.Contravariant Methodsmempty :: Equivalence a Source mappend :: Equivalence a -> Equivalence a -> Equivalence a Source mconcat :: [Equivalence a] -> Equivalence a Source |
|
| Monoid (Predicate a) Source |
|
| Monoid a => Monoid (Identity a) Source | Since: base-4.9.0.0 |
| Monoid (First a) Source | Since: base-2.1 |
| Monoid (Last a) Source | Since: base-2.1 |
| Monoid a => Monoid (Down a) Source | Since: base-4.11.0.0 |
| (Ord a, Bounded a) => Monoid (Max a) Source | Since: base-4.9.0.0 |
| (Ord a, Bounded a) => Monoid (Min a) Source | Since: base-4.9.0.0 |
| Monoid m => Monoid (WrappedMonoid m) Source | Since: base-4.9.0.0 |
|
Defined in Data.Semigroup Methodsmempty :: WrappedMonoid m Source mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source mconcat :: [WrappedMonoid m] -> WrappedMonoid m Source |
|
| Monoid a => Monoid (Dual a) Source | Since: base-2.1 |
| Monoid (Endo a) Source | Since: base-2.1 |
| Num a => Monoid (Product a) Source | Since: base-2.1 |
| Num a => Monoid (Sum a) Source | Since: base-2.1 |
| Monoid a => Monoid (STM a) Source | Since: base-4.17.0.0 |
| (Generic a, Monoid (Rep a ())) => Monoid (Generically a) Source | Since: base-4.17.0.0 |
|
Defined in GHC.Generics Methodsmempty :: Generically a Source mappend :: Generically a -> Generically a -> Generically a Source mconcat :: [Generically a] -> Generically a Source |
|
| Monoid p => Monoid (Par1 p) Source | Since: base-4.12.0.0 |
| Monoid a => Monoid (IO a) Source | Since: base-4.9.0.0 |
| Semigroup a => Monoid (Maybe a) Source | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
| Monoid a => Monoid (a) Source | Since: base-4.15 |
| Monoid [a] Source | Since: base-2.1 |
| Monoid a => Monoid (Op a b) Source |
|
| Monoid (Proxy s) Source | Since: base-4.7.0.0 |
| Monoid (U1 p) Source | Since: base-4.12.0.0 |
| Monoid a => Monoid (ST s a) Source | Since: base-4.11.0.0 |
| Monoid b => Monoid (a -> b) Source | Since: base-2.1 |
| (Monoid a, Monoid b) => Monoid (a, b) Source | Since: base-2.1 |
| Monoid a => Monoid (Const a b) Source | Since: base-4.9.0.0 |
| (Applicative f, Monoid a) => Monoid (Ap f a) Source | Since: base-4.12.0.0 |
| Alternative f => Monoid (Alt f a) Source | Since: base-4.8.0.0 |
| Monoid (f p) => Monoid (Rec1 f p) Source | Since: base-4.12.0.0 |