Movatterモバイル変換


[0]ホーム

URL:


base-4.12.0.0: Basic libraries

Copyright(c) The University of Glasgow 2001
LicenseBSD-style (see the file libraries/base/LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Monad

Contents

Description

TheFunctor,Monad andMonadPlus classes, with some useful operations on monads.

Synopsis

Functor and monad classes

classFunctor fwhereSource#

TheFunctor class is used for types that can be mapped over.Instances ofFunctor should satisfy the following laws:

fmap id  ==  idfmap (f . g)  ==  fmap f . fmap g

The instances ofFunctor for lists,Maybe andIOsatisfy these laws.

Methods

fmap :: (a -> b) -> f a -> f bSource#

Instances
Functor []Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

fmap :: (a -> b) -> [a] -> [b]Source#

(<$) :: a -> [b] -> [a]Source#

FunctorMaybeSource#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

fmap :: (a -> b) ->Maybe a ->Maybe bSource#

(<$) :: a ->Maybe b ->Maybe aSource#

FunctorIOSource#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

fmap :: (a -> b) ->IO a ->IO bSource#

(<$) :: a ->IO b ->IO aSource#

FunctorPar1Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->Par1 a ->Par1 bSource#

(<$) :: a ->Par1 b ->Par1 aSource#

FunctorNonEmptySource#

Since: 4.9.0.0

Instance details

Defined inGHC.Base

Methods

fmap :: (a -> b) ->NonEmpty a ->NonEmpty bSource#

(<$) :: a ->NonEmpty b ->NonEmpty aSource#

FunctorReadPSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadP

Methods

fmap :: (a -> b) ->ReadP a ->ReadP bSource#

(<$) :: a ->ReadP b ->ReadP aSource#

FunctorReadPrecSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadPrec

Methods

fmap :: (a -> b) ->ReadPrec a ->ReadPrec bSource#

(<$) :: a ->ReadPrec b ->ReadPrec aSource#

FunctorDownSource#

Since: 4.11.0.0

Instance details

Defined inData.Ord

Methods

fmap :: (a -> b) ->Down a ->Down bSource#

(<$) :: a ->Down b ->Down aSource#

FunctorProductSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

fmap :: (a -> b) ->Product a ->Product bSource#

(<$) :: a ->Product b ->Product aSource#

FunctorSumSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

fmap :: (a -> b) ->Sum a ->Sum bSource#

(<$) :: a ->Sum b ->Sum aSource#

FunctorDualSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

fmap :: (a -> b) ->Dual a ->Dual bSource#

(<$) :: a ->Dual b ->Dual aSource#

FunctorLastSource#

Since: 4.8.0.0

Instance details

Defined inData.Monoid

Methods

fmap :: (a -> b) ->Last a ->Last bSource#

(<$) :: a ->Last b ->Last aSource#

FunctorFirstSource#

Since: 4.8.0.0

Instance details

Defined inData.Monoid

Methods

fmap :: (a -> b) ->First a ->First bSource#

(<$) :: a ->First b ->First aSource#

FunctorSTMSource#

Since: 4.3.0.0

Instance details

Defined inGHC.Conc.Sync

Methods

fmap :: (a -> b) ->STM a ->STM bSource#

(<$) :: a ->STM b ->STM aSource#

FunctorHandlerSource#

Since: 4.6.0.0

Instance details

Defined inControl.Exception

Methods

fmap :: (a -> b) ->Handler a ->Handler bSource#

(<$) :: a ->Handler b ->Handler aSource#

FunctorIdentitySource#

Since: 4.8.0.0

Instance details

Defined inData.Functor.Identity

Methods

fmap :: (a -> b) ->Identity a ->Identity bSource#

(<$) :: a ->Identity b ->Identity aSource#

FunctorZipListSource#

Since: 2.1

Instance details

Defined inControl.Applicative

Methods

fmap :: (a -> b) ->ZipList a ->ZipList bSource#

(<$) :: a ->ZipList b ->ZipList aSource#

FunctorArgDescrSource#

Since: 4.6.0.0

Instance details

Defined inSystem.Console.GetOpt

Methods

fmap :: (a -> b) ->ArgDescr a ->ArgDescr bSource#

(<$) :: a ->ArgDescr b ->ArgDescr aSource#

FunctorOptDescrSource#

Since: 4.6.0.0

Instance details

Defined inSystem.Console.GetOpt

Methods

fmap :: (a -> b) ->OptDescr a ->OptDescr bSource#

(<$) :: a ->OptDescr b ->OptDescr aSource#

FunctorArgOrderSource#

Since: 4.6.0.0

Instance details

Defined inSystem.Console.GetOpt

Methods

fmap :: (a -> b) ->ArgOrder a ->ArgOrder bSource#

(<$) :: a ->ArgOrder b ->ArgOrder aSource#

FunctorOptionSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a -> b) ->Option a ->Option bSource#

(<$) :: a ->Option b ->Option aSource#

FunctorLastSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a -> b) ->Last a ->Last bSource#

(<$) :: a ->Last b ->Last aSource#

FunctorFirstSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a -> b) ->First a ->First bSource#

(<$) :: a ->First b ->First aSource#

FunctorMaxSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a -> b) ->Max a ->Max bSource#

(<$) :: a ->Max b ->Max aSource#

FunctorMinSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a -> b) ->Min a ->Min bSource#

(<$) :: a ->Min b ->Min aSource#

FunctorComplexSource#

Since: 4.9.0.0

Instance details

Defined inData.Complex

Methods

fmap :: (a -> b) ->Complex a ->Complex bSource#

(<$) :: a ->Complex b ->Complex aSource#

Functor (Either a)Source#

Since: 3.0

Instance details

Defined inData.Either

Methods

fmap :: (a0 -> b) ->Either a a0 ->Either a bSource#

(<$) :: a0 ->Either a b ->Either a a0Source#

Functor (V1 ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->V1 a ->V1 bSource#

(<$) :: a ->V1 b ->V1 aSource#

Functor (U1 ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->U1 a ->U1 bSource#

(<$) :: a ->U1 b ->U1 aSource#

Functor ((,) a)Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

fmap :: (a0 -> b) -> (a, a0) -> (a, b)Source#

(<$) :: a0 -> (a, b) -> (a, a0)Source#

Functor (ST s)Source#

Since: 2.1

Instance details

Defined inGHC.ST

Methods

fmap :: (a -> b) ->ST s a ->ST s bSource#

(<$) :: a ->ST s b ->ST s aSource#

Functor (Proxy ::Type ->Type)Source#

Since: 4.7.0.0

Instance details

Defined inData.Proxy

Methods

fmap :: (a -> b) ->Proxy a ->Proxy bSource#

(<$) :: a ->Proxy b ->Proxy aSource#

Arrow a =>Functor (ArrowMonad a)Source#

Since: 4.6.0.0

Instance details

Defined inControl.Arrow

Methods

fmap :: (a0 -> b) ->ArrowMonad a a0 ->ArrowMonad a bSource#

(<$) :: a0 ->ArrowMonad a b ->ArrowMonad a a0Source#

Monad m =>Functor (WrappedMonad m)Source#

Since: 2.1

Instance details

Defined inControl.Applicative

Methods

fmap :: (a -> b) ->WrappedMonad m a ->WrappedMonad m bSource#

(<$) :: a ->WrappedMonad m b ->WrappedMonad m aSource#

Functor (ST s)Source#

Since: 2.1

Instance details

Defined inControl.Monad.ST.Lazy.Imp

Methods

fmap :: (a -> b) ->ST s a ->ST s bSource#

(<$) :: a ->ST s b ->ST s aSource#

Functor (Arg a)Source#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

fmap :: (a0 -> b) ->Arg a a0 ->Arg a bSource#

(<$) :: a0 ->Arg a b ->Arg a a0Source#

Functor f =>Functor (Rec1 f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->Rec1 f a ->Rec1 f bSource#

(<$) :: a ->Rec1 f b ->Rec1 f aSource#

Functor (URecChar ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URecChar a ->URecChar bSource#

(<$) :: a ->URecChar b ->URecChar aSource#

Functor (URecDouble ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URecDouble a ->URecDouble bSource#

(<$) :: a ->URecDouble b ->URecDouble aSource#

Functor (URecFloat ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URecFloat a ->URecFloat bSource#

(<$) :: a ->URecFloat b ->URecFloat aSource#

Functor (URecInt ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URecInt a ->URecInt bSource#

(<$) :: a ->URecInt b ->URecInt aSource#

Functor (URecWord ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URecWord a ->URecWord bSource#

(<$) :: a ->URecWord b ->URecWord aSource#

Functor (URec (Ptr ()) ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->URec (Ptr ()) a ->URec (Ptr ()) bSource#

(<$) :: a ->URec (Ptr ()) b ->URec (Ptr ()) aSource#

Functor f =>Functor (Alt f)Source#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

fmap :: (a -> b) ->Alt f a ->Alt f bSource#

(<$) :: a ->Alt f b ->Alt f aSource#

Functor f =>Functor (Ap f)Source#

Since: 4.12.0.0

Instance details

Defined inData.Monoid

Methods

fmap :: (a -> b) ->Ap f a ->Ap f bSource#

(<$) :: a ->Ap f b ->Ap f aSource#

Functor (Const m ::Type ->Type)Source#

Since: 2.1

Instance details

Defined inData.Functor.Const

Methods

fmap :: (a -> b) ->Const m a ->Const m bSource#

(<$) :: a ->Const m b ->Const m aSource#

Arrow a =>Functor (WrappedArrow a b)Source#

Since: 2.1

Instance details

Defined inControl.Applicative

Methods

fmap :: (a0 -> b0) ->WrappedArrow a b a0 ->WrappedArrow a b b0Source#

(<$) :: a0 ->WrappedArrow a b b0 ->WrappedArrow a b a0Source#

Functor ((->) r ::Type ->Type)Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

fmap :: (a -> b) -> (r -> a) -> r -> bSource#

(<$) :: a -> (r -> b) -> r -> aSource#

Functor (K1 i c ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->K1 i c a ->K1 i c bSource#

(<$) :: a ->K1 i c b ->K1 i c aSource#

(Functor f,Functor g) =>Functor (f:+: g)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) -> (f:+: g) a -> (f:+: g) bSource#

(<$) :: a -> (f:+: g) b -> (f:+: g) aSource#

(Functor f,Functor g) =>Functor (f:*: g)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) -> (f:*: g) a -> (f:*: g) bSource#

(<$) :: a -> (f:*: g) b -> (f:*: g) aSource#

(Functor f,Functor g) =>Functor (Sum f g)Source#

Since: 4.9.0.0

Instance details

Defined inData.Functor.Sum

Methods

fmap :: (a -> b) ->Sum f g a ->Sum f g bSource#

(<$) :: a ->Sum f g b ->Sum f g aSource#

(Functor f,Functor g) =>Functor (Product f g)Source#

Since: 4.9.0.0

Instance details

Defined inData.Functor.Product

Methods

fmap :: (a -> b) ->Product f g a ->Product f g bSource#

(<$) :: a ->Product f g b ->Product f g aSource#

Functor f =>Functor (M1 i c f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) ->M1 i c f a ->M1 i c f bSource#

(<$) :: a ->M1 i c f b ->M1 i c f aSource#

(Functor f,Functor g) =>Functor (f:.: g)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

fmap :: (a -> b) -> (f:.: g) a -> (f:.: g) bSource#

(<$) :: a -> (f:.: g) b -> (f:.: g) aSource#

(Functor f,Functor g) =>Functor (Compose f g)Source#

Since: 4.9.0.0

Instance details

Defined inData.Functor.Compose

Methods

fmap :: (a -> b) ->Compose f g a ->Compose f g bSource#

(<$) :: a ->Compose f g b ->Compose f g aSource#

classApplicative m =>Monad mwhereSource#

TheMonad class defines the basic operations over amonad,a concept from a branch of mathematics known ascategory theory.From the perspective of a Haskell programmer, however, it is best tothink of a monad as anabstract datatype of actions.Haskell'sdo expressions provide a convenient syntax for writingmonadic expressions.

Instances ofMonad should satisfy the following laws:

Furthermore, theMonad andApplicative operations should relate as follows:

The above laws imply:

and thatpure and (<*>) satisfy the applicative functor laws.

The instances ofMonad for lists,Maybe andIOdefined in thePrelude satisfy these laws.

Minimal complete definition

(>>=)

Methods

(>>=) ::forall a b. m a -> (a -> m b) -> m binfixl 1Source#

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 binfixl 1Source#

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.

return :: a -> m aSource#

Inject a value into the monadic type.

fail ::String -> m aSource#

Fail with a message. This operation is not part of the mathematical definition of a monad, but is invoked on pattern-match failure in ado expression.

As part of the MonadFail proposal (MFP), this function is moved to its own classMonadFail (seeControl.Monad.Fail for more details). The definition here will be removed in a future release.

Instances
Monad []Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

(>>=) :: [a] -> (a -> [b]) -> [b]Source#

(>>) :: [a] -> [b] -> [b]Source#

return :: a -> [a]Source#

fail ::String -> [a]Source#

MonadMaybeSource#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

(>>=) ::Maybe a -> (a ->Maybe b) ->Maybe bSource#

(>>) ::Maybe a ->Maybe b ->Maybe bSource#

return :: a ->Maybe aSource#

fail ::String ->Maybe aSource#

MonadIOSource#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

(>>=) ::IO a -> (a ->IO b) ->IO bSource#

(>>) ::IO a ->IO b ->IO bSource#

return :: a ->IO aSource#

fail ::String ->IO aSource#

MonadPar1Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

(>>=) ::Par1 a -> (a ->Par1 b) ->Par1 bSource#

(>>) ::Par1 a ->Par1 b ->Par1 bSource#

return :: a ->Par1 aSource#

fail ::String ->Par1 aSource#

MonadNonEmptySource#

Since: 4.9.0.0

Instance details

Defined inGHC.Base

MonadReadPSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadP

Methods

(>>=) ::ReadP a -> (a ->ReadP b) ->ReadP bSource#

(>>) ::ReadP a ->ReadP b ->ReadP bSource#

return :: a ->ReadP aSource#

fail ::String ->ReadP aSource#

MonadReadPrecSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadPrec

MonadDownSource#

Since: 4.11.0.0

Instance details

Defined inData.Ord

Methods

(>>=) ::Down a -> (a ->Down b) ->Down bSource#

(>>) ::Down a ->Down b ->Down bSource#

return :: a ->Down aSource#

fail ::String ->Down aSource#

MonadProductSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

MonadSumSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

(>>=) ::Sum a -> (a ->Sum b) ->Sum bSource#

(>>) ::Sum a ->Sum b ->Sum bSource#

return :: a ->Sum aSource#

fail ::String ->Sum aSource#

MonadDualSource#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

(>>=) ::Dual a -> (a ->Dual b) ->Dual bSource#

(>>) ::Dual a ->Dual b ->Dual bSource#

return :: a ->Dual aSource#

fail ::String ->Dual aSource#

MonadLastSource#

Since: 4.8.0.0

Instance details

Defined inData.Monoid

Methods

(>>=) ::Last a -> (a ->Last b) ->Last bSource#

(>>) ::Last a ->Last b ->Last bSource#

return :: a ->Last aSource#

fail ::String ->Last aSource#

MonadFirstSource#

Since: 4.8.0.0

Instance details

Defined inData.Monoid

Methods

(>>=) ::First a -> (a ->First b) ->First bSource#

(>>) ::First a ->First b ->First bSource#

return :: a ->First aSource#

fail ::String ->First aSource#

MonadSTMSource#

Since: 4.3.0.0

Instance details

Defined inGHC.Conc.Sync

Methods

(>>=) ::STM a -> (a ->STM b) ->STM bSource#

(>>) ::STM a ->STM b ->STM bSource#

return :: a ->STM aSource#

fail ::String ->STM aSource#

MonadIdentitySource#

Since: 4.8.0.0

Instance details

Defined inData.Functor.Identity

MonadOptionSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

MonadLastSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

(>>=) ::Last a -> (a ->Last b) ->Last bSource#

(>>) ::Last a ->Last b ->Last bSource#

return :: a ->Last aSource#

fail ::String ->Last aSource#

MonadFirstSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

(>>=) ::First a -> (a ->First b) ->First bSource#

(>>) ::First a ->First b ->First bSource#

return :: a ->First aSource#

fail ::String ->First aSource#

MonadMaxSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

(>>=) ::Max a -> (a ->Max b) ->Max bSource#

(>>) ::Max a ->Max b ->Max bSource#

return :: a ->Max aSource#

fail ::String ->Max aSource#

MonadMinSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

Methods

(>>=) ::Min a -> (a ->Min b) ->Min bSource#

(>>) ::Min a ->Min b ->Min bSource#

return :: a ->Min aSource#

fail ::String ->Min aSource#

MonadComplexSource#

Since: 4.9.0.0

Instance details

Defined inData.Complex

Monad (Either e)Source#

Since: 4.4.0.0

Instance details

Defined inData.Either

Methods

(>>=) ::Either e a -> (a ->Either e b) ->Either e bSource#

(>>) ::Either e a ->Either e b ->Either e bSource#

return :: a ->Either e aSource#

fail ::String ->Either e aSource#

Monad (U1 ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

(>>=) ::U1 a -> (a ->U1 b) ->U1 bSource#

(>>) ::U1 a ->U1 b ->U1 bSource#

return :: a ->U1 aSource#

fail ::String ->U1 aSource#

Monoid a =>Monad ((,) a)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Base

Methods

(>>=) :: (a, a0) -> (a0 -> (a, b)) -> (a, b)Source#

(>>) :: (a, a0) -> (a, b) -> (a, b)Source#

return :: a0 -> (a, a0)Source#

fail ::String -> (a, a0)Source#

Monad (ST s)Source#

Since: 2.1

Instance details

Defined inGHC.ST

Methods

(>>=) ::ST s a -> (a ->ST s b) ->ST s bSource#

(>>) ::ST s a ->ST s b ->ST s bSource#

return :: a ->ST s aSource#

fail ::String ->ST s aSource#

Monad (Proxy ::Type ->Type)Source#

Since: 4.7.0.0

Instance details

Defined inData.Proxy

Methods

(>>=) ::Proxy a -> (a ->Proxy b) ->Proxy bSource#

(>>) ::Proxy a ->Proxy b ->Proxy bSource#

return :: a ->Proxy aSource#

fail ::String ->Proxy aSource#

ArrowApply a =>Monad (ArrowMonad a)Source#

Since: 2.1

Instance details

Defined inControl.Arrow

Monad m =>Monad (WrappedMonad m)Source#

Since: 4.7.0.0

Instance details

Defined inControl.Applicative

Monad (ST s)Source#

Since: 2.1

Instance details

Defined inControl.Monad.ST.Lazy.Imp

Methods

(>>=) ::ST s a -> (a ->ST s b) ->ST s bSource#

(>>) ::ST s a ->ST s b ->ST s bSource#

return :: a ->ST s aSource#

fail ::String ->ST s aSource#

Monad f =>Monad (Rec1 f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

(>>=) ::Rec1 f a -> (a ->Rec1 f b) ->Rec1 f bSource#

(>>) ::Rec1 f a ->Rec1 f b ->Rec1 f bSource#

return :: a ->Rec1 f aSource#

fail ::String ->Rec1 f aSource#

Monad f =>Monad (Alt f)Source#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

(>>=) ::Alt f a -> (a ->Alt f b) ->Alt f bSource#

(>>) ::Alt f a ->Alt f b ->Alt f bSource#

return :: a ->Alt f aSource#

fail ::String ->Alt f aSource#

Monad f =>Monad (Ap f)Source#

Since: 4.12.0.0

Instance details

Defined inData.Monoid

Methods

(>>=) ::Ap f a -> (a ->Ap f b) ->Ap f bSource#

(>>) ::Ap f a ->Ap f b ->Ap f bSource#

return :: a ->Ap f aSource#

fail ::String ->Ap f aSource#

Monad ((->) r ::Type ->Type)Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

(>>=) :: (r -> a) -> (a -> r -> b) -> r -> bSource#

(>>) :: (r -> a) -> (r -> b) -> r -> bSource#

return :: a -> r -> aSource#

fail ::String -> r -> aSource#

(Monad f,Monad g) =>Monad (f:*: g)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

(>>=) :: (f:*: g) a -> (a -> (f:*: g) b) -> (f:*: g) bSource#

(>>) :: (f:*: g) a -> (f:*: g) b -> (f:*: g) bSource#

return :: a -> (f:*: g) aSource#

fail ::String -> (f:*: g) aSource#

(Monad f,Monad g) =>Monad (Product f g)Source#

Since: 4.9.0.0

Instance details

Defined inData.Functor.Product

Methods

(>>=) ::Product f g a -> (a ->Product f g b) ->Product f g bSource#

(>>) ::Product f g a ->Product f g b ->Product f g bSource#

return :: a ->Product f g aSource#

fail ::String ->Product f g aSource#

Monad f =>Monad (M1 i c f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

(>>=) ::M1 i c f a -> (a ->M1 i c f b) ->M1 i c f bSource#

(>>) ::M1 i c f a ->M1 i c f b ->M1 i c f bSource#

return :: a ->M1 i c f aSource#

fail ::String ->M1 i c f aSource#

class (Alternative m,Monad m) =>MonadPlus mwhereSource#

Monads that also support choice and failure.

Minimal complete definition

Nothing

Methods

mzero :: m aSource#

The identity ofmplus. It should also satisfy the equations

mzero >>= f  =  mzerov >> mzero   =  mzero

The default definition is

mzero =empty

mplus :: m a -> m a -> m aSource#

An associative operation. The default definition is

mplus = (<|>)
Instances
MonadPlus []Source#

Since: 2.1

Instance details

Defined inGHC.Base

Methods

mzero :: [a]Source#

mplus :: [a] -> [a] -> [a]Source#

MonadPlusMaybeSource#

Since: 2.1

Instance details

Defined inGHC.Base

MonadPlusIOSource#

Since: 4.9.0.0

Instance details

Defined inGHC.Base

Methods

mzero ::IO aSource#

mplus ::IO a ->IO a ->IO aSource#

MonadPlusReadPSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadP

MonadPlusReadPrecSource#

Since: 2.1

Instance details

Defined inText.ParserCombinators.ReadPrec

MonadPlusSTMSource#

Since: 4.3.0.0

Instance details

Defined inGHC.Conc.Sync

Methods

mzero ::STM aSource#

mplus ::STM a ->STM a ->STM aSource#

MonadPlusOptionSource#

Since: 4.9.0.0

Instance details

Defined inData.Semigroup

MonadPlus (U1 ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

mzero ::U1 aSource#

mplus ::U1 a ->U1 a ->U1 aSource#

MonadPlus (Proxy ::Type ->Type)Source#

Since: 4.9.0.0

Instance details

Defined inData.Proxy

(ArrowApply a,ArrowPlus a) =>MonadPlus (ArrowMonad a)Source#

Since: 4.6.0.0

Instance details

Defined inControl.Arrow

MonadPlus f =>MonadPlus (Rec1 f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

mzero ::Rec1 f aSource#

mplus ::Rec1 f a ->Rec1 f a ->Rec1 f aSource#

MonadPlus f =>MonadPlus (Alt f)Source#

Since: 4.8.0.0

Instance details

Defined inData.Semigroup.Internal

Methods

mzero ::Alt f aSource#

mplus ::Alt f a ->Alt f a ->Alt f aSource#

MonadPlus f =>MonadPlus (Ap f)Source#

Since: 4.12.0.0

Instance details

Defined inData.Monoid

Methods

mzero ::Ap f aSource#

mplus ::Ap f a ->Ap f a ->Ap f aSource#

(MonadPlus f,MonadPlus g) =>MonadPlus (f:*: g)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

mzero :: (f:*: g) aSource#

mplus :: (f:*: g) a -> (f:*: g) a -> (f:*: g) aSource#

(MonadPlus f,MonadPlus g) =>MonadPlus (Product f g)Source#

Since: 4.9.0.0

Instance details

Defined inData.Functor.Product

Methods

mzero ::Product f g aSource#

mplus ::Product f g a ->Product f g a ->Product f g aSource#

MonadPlus f =>MonadPlus (M1 i c f)Source#

Since: 4.9.0.0

Instance details

Defined inGHC.Generics

Methods

mzero ::M1 i c f aSource#

mplus ::M1 i c f a ->M1 i c f a ->M1 i c f aSource#

Functions

Naming conventions

The functions in this library use the following naming conventions:

  • A postfix 'M' always stands for a function in the Kleisli category: The monad type constructorm is added to function results (modulo currying) and nowhere else. So, for example,
filter  ::              (a ->   Bool) -> [a] ->   [a]filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
  • A postfix '_' changes the result type from(m a) to(m ()). Thus, for example:
sequence  :: Monad m => [m a] -> m [a]sequence_ :: Monad m => [m a] -> m ()
  • A prefix 'm' generalizes an existing function to a monadic form. Thus, for example:
filter  ::                (a -> Bool) -> [a] -> [a]mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a

BasicMonad functions

mapM :: (Traversable t,Monad m) => (a -> m b) -> t a -> m (t b)Source#

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results. For a version that ignores the results seemapM_.

mapM_ :: (Foldable t,Monad m) => (a -> m b) -> t a -> m ()Source#

Map each element of a structure to a monadic action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results seemapM.

As of base 4.8.0.0,mapM_ is justtraverse_, specialized toMonad.

forM :: (Traversable t,Monad m) => t a -> (a -> m b) -> m (t b)Source#

forM ismapM with its arguments flipped. For a version that ignores the results seeforM_.

forM_ :: (Foldable t,Monad m) => t a -> (a -> m b) -> m ()Source#

forM_ ismapM_ with its arguments flipped. For a version that doesn't ignore the results seeforM.

As of base 4.8.0.0,forM_ is justfor_, specialized toMonad.

sequence :: (Traversable t,Monad m) => t (m a) -> m (t a)Source#

Evaluate each monadic action in the structure from left to right, and collect the results. For a version that ignores the results seesequence_.

sequence_ :: (Foldable t,Monad m) => t (m a) -> m ()Source#

Evaluate each monadic action in the structure from left to right, and ignore the results. For a version that doesn't ignore the results seesequence.

As of base 4.8.0.0,sequence_ is justsequenceA_, specialized toMonad.

(=<<) ::Monad m => (a -> m b) -> m a -> m binfixr 1Source#

Same as>>=, but with the arguments interchanged.

(>=>) ::Monad m => (a -> m b) -> (b -> m c) -> a -> m cinfixr 1Source#

Left-to-right composition of Kleisli arrows.

(<=<) ::Monad m => (b -> m c) -> (a -> m b) -> a -> m cinfixr 1Source#

Right-to-left composition of Kleisli arrows.(>=>), with the arguments flipped.

Note how this operator resembles function composition(.):

(.)   ::            (b ->   c) -> (a ->   b) -> a ->   c(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c

forever ::Applicative f => f a -> f bSource#

Repeat an action indefinitely.

Examples

Expand

A common use offorever is to process input from network sockets,Handles, and channels (e.g.MVar andChan).

For example, here is how we might implement anecho server, usingforever both to listen for client connections on a network socket and to echo client input on client connection handles:

echoServer :: Socket -> IO ()echoServer socket =forever $ do  client <- accept socketforkFinally (echo client) (\_ -> hClose client)  where    echo :: Handle -> IO ()    echo client =forever $      hGetLine client >>= hPutStrLn client

void ::Functor f => f a -> f ()Source#

void value discards or ignores the result of evaluation, such as the return value of anIO action.

Examples

Expand

Replace the contents of aMaybeInt with unit:

>>>void NothingNothing>>>void (Just 3)Just ()

Replace the contents of anEitherIntInt with unit, resulting in anEitherInt '()':

>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()

Replace every element of a list with unit:

>>>void [1,2,3][(),(),()]

Replace the second element of a pair with unit:

>>>void (1,2)(1,())

Discard the result of anIO action:

>>>mapM print [1,2]12[(),()]>>>void $ mapM print [1,2]12

Generalisations of list functions

join ::Monad m => m (m a) -> m aSource#

Thejoin 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

Expand

A common use ofjoin is to run anIO computation returned from anSTM transaction, sinceSTM transactions can't performIO directly. Recall that

atomically :: STM a -> IO a

is used to runSTM transactions atomically. So, by specializing the types ofatomically andjoin to

atomically :: STM (IO b) -> IO (IO b)join       :: IO (IO b)  -> IO b

we can compose them as

join .atomically :: STM (IO b) -> IO b

to run anSTM transaction and theIO action it returns.

msum :: (Foldable t,MonadPlus m) => t (m a) -> m aSource#

The sum of a collection of actions, generalizingconcat. As of base 4.8.0.0,msum is justasum, specialized toMonadPlus.

mfilter ::MonadPlus m => (a ->Bool) -> m a -> m aSource#

DirectMonadPlus equivalent offilter.

Examples

Expand

Thefilter function is justmfilter specialized to the list monad:

filter = (mfilter :: (a -> Bool) -> [a] -> [a] )

An example usingmfilter with theMaybe monad:

>>> mfilter odd (Just 1)Just 1>>> mfilter odd (Just 2)Nothing

filterM ::Applicative m => (a -> mBool) -> [a] -> m [a]Source#

This generalizes the list-basedfilter function.

mapAndUnzipM ::Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])Source#

ThemapAndUnzipM function maps its first argument over a list, returning the result as a pair of lists. This function is mainly used with complicated data structures or a state-transforming monad.

zipWithM ::Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]Source#

ThezipWithM function generalizeszipWith to arbitrary applicative functors.

zipWithM_ ::Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()Source#

zipWithM_ is the extension ofzipWithM which ignores the final result.

foldM :: (Foldable t,Monad m) => (b -> a -> m b) -> b -> t a -> m bSource#

ThefoldM function is analogous tofoldl, except that its result isencapsulated in a monad. Note thatfoldM works from left-to-right overthe list arguments. This could be an issue where(>>) and the `foldedfunction' are not commutative.

foldM f a1 [x1, x2, ..., xm]==do  a2 <- f a1 x1  a3 <- f a2 x2  ...  f am xm

If right-to-left evaluation is required, the input list should be reversed.

Note:foldM is the same asfoldlM

foldM_ :: (Foldable t,Monad m) => (b -> a -> m b) -> b -> t a -> m ()Source#

LikefoldM, but discards the result.

replicateM ::Applicative m =>Int -> m a -> m [a]Source#

replicateM n act performs the actionn times, gathering the results.

replicateM_ ::Applicative m =>Int -> m a -> m ()Source#

LikereplicateM, but discards the result.

Conditional execution of monadic expressions

guard ::Alternative f =>Bool -> f ()Source#

Conditional failure ofAlternative computations. Defined by

guard True  =pure ()guard False =empty

Examples

Expand

Common uses ofguard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in anAlternative-based parser.

As an example of signaling an error in the error monadMaybe, consider a safe division functionsafeDiv x y that returnsNothing when the denominatory is zero andJust (x `div` y) otherwise. For example:

>>> safeDiv 4 0Nothing>>> safeDiv 4 2Just 2

A definition ofsafeDiv using guards, but notguard:

safeDiv :: Int -> Int -> Maybe IntsafeDiv x y | y /= 0    = Just (x `div` y)            | otherwise = Nothing

A definition ofsafeDiv usingguard andMonaddo-notation:

safeDiv :: Int -> Int -> Maybe IntsafeDiv x y = do  guard (y /= 0)  return (x `div` y)

when ::Applicative f =>Bool -> f () -> f ()Source#

Conditional execution ofApplicative expressions. For example,

when debug (putStrLn "Debugging")

will output the stringDebugging if the Boolean valuedebug isTrue, and otherwise do nothing.

unless ::Applicative f =>Bool -> f () -> f ()Source#

The reverse ofwhen.

Monadic lifting operators

liftM ::Monad m => (a1 -> r) -> m a1 -> m rSource#

Promote a function to a monad.

liftM2 ::Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m rSource#

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 rSource#

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 rSource#

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 rSource#

Promote a function to a monad, scanning the monadic arguments from left to right (cf.liftM2).

ap ::Monad m => m (a -> b) -> m a -> m bSource#

In many situations, theliftM operations can be replaced by uses ofap, which promotes function application.

return f `ap` x1 `ap` ... `ap` xn

is equivalent to

liftMn f x1 x2 ... xn

Strict monadic functions

(<$!>) ::Monad m => (a -> b) -> m a -> m binfixl 4Source#

Strict version of<$>.

Since: 4.8.0.0

Produced byHaddock version 2.20.0


[8]ページ先頭

©2009-2025 Movatter.jp