Control.Bind
#Bind
class (Apply m) <= Bind m whereThe Bind type class extends the Apply type class with a
"bind" operation (>>=) which composes computations in sequence, using
the return value of one computation to determine the next computation.
The >>= operator can also be expressed using do notation, as follows:
x >>= f = do y <- x
f y
where the function argument of f is given the name y.
Instances must satisfy the following law in addition to the Apply
laws:
- Associativity:
(x >>= f) >>= g = x >>= (\k -> f k >>= g)
Associativity tells us that we can regroup operations which use do
notation so that we can unambiguously write, for example:
do x <- m1
y <- m2 x
m3 x y
Members
bind :: forall a b. m a -> (a -> m b) -> m b
Instances
#(>>=)
Operator alias for Control.Bind.bind (left-associative / precedence 1)
#bindFlipped
bindFlipped :: forall m a b. Bind m => (a -> m b) -> m a -> m bbindFlipped is bind with its arguments reversed. For example:
print =<< random
#(=<<)
Operator alias for Control.Bind.bindFlipped (right-associative / precedence 1)
#Discard
#join
#composeKleisli
composeKleisli :: forall a b c m. Bind m => (a -> m b) -> (b -> m c) -> a -> m cForwards Kleisli composition.
For example:
import Data.Array (head, tail)
third = tail >=> tail >=> head
#(>=>)
Operator alias for Control.Bind.composeKleisli (right-associative / precedence 1)
#composeKleisliFlipped
composeKleisliFlipped :: forall a b c m. Bind m => (b -> m c) -> (a -> m b) -> a -> m cBackwards Kleisli composition.
#(<=<)
Operator alias for Control.Bind.composeKleisliFlipped (right-associative / precedence 1)
#ifM
Re-exports from Control.Applicative
#Applicative
class (Apply f) <= Applicative f whereThe Applicative type class extends the Apply type class
with a pure function, which can be used to create values of type f a
from values of type a.
Where Apply provides the ability to lift functions of two or
more arguments to functions whose arguments are wrapped using f, and
Functor provides the ability to lift functions of one
argument, pure can be seen as the function which lifts functions of
zero arguments. That is, Applicative functors support a lifting
operation for any number of function arguments.
Instances must satisfy the following laws in addition to the Apply
laws:
- Identity:
(pure identity) <*> v = v - Composition:
pure (<<<) <*> f <*> g <*> h = f <*> (g <*> h) - Homomorphism:
(pure f) <*> (pure x) = pure (f x) - Interchange:
u <*> (pure y) = (pure (_ $ y)) <*> u
Members
pure :: forall a. a -> f a
Instances
#when
when :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action when a condition is true.
#unless
unless :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action unless a condition is true.
#liftA1
liftA1 :: forall f a b. Applicative f => (a -> b) -> f a -> f bliftA1 provides a default implementation of (<$>) for any
Applicative functor, without using (<$>) as provided
by the Functor-Applicative superclass
relationship.
liftA1 can therefore be used to write Functor instances
as follows:
instance functorF :: Functor F where
map = liftA1
Re-exports from Control.Apply
#Apply
class (Functor f) <= Apply f whereThe Apply class provides the (<*>) which is used to apply a function
to an argument under a type constructor.
Apply can be used to lift functions of two or more arguments to work on
values wrapped with the type constructor f. It might also be understood
in terms of the lift2 function:
lift2 :: forall f a b c. Apply f => (a -> b -> c) -> f a -> f b -> f c
lift2 f a b = f <$> a <*> b
(<*>) is recovered from lift2 as lift2 ($). That is, (<*>) lifts
the function application operator ($) to arguments wrapped with the
type constructor f.
Instances must satisfy the following law in addition to the Functor
laws:
- Associative composition:
(<<<) <$> f <*> g <*> h = f <*> (g <*> h)
Formally, Apply represents a strong lax semi-monoidal endofunctor.
Members
apply :: forall a b. f (a -> b) -> f a -> f b
Instances
#(<*>)
Operator alias for Control.Apply.apply (left-associative / precedence 4)
#(<*)
Operator alias for Control.Apply.applyFirst (left-associative / precedence 4)
#(*>)
Operator alias for Control.Apply.applySecond (left-associative / precedence 4)
Re-exports from Data.Functor
#Functor
class Functor f whereA Functor is a type constructor which supports a mapping operation
map.
map can be used to turn functions a -> b into functions
f a -> f b whose argument and return types use the type constructor f
to represent some computational context.
Instances must satisfy the following laws:
- Identity:
map identity = identity - Composition:
map (f <<< g) = map f <<< map g
Members
map :: forall a b. (a -> b) -> f a -> f b
Instances
#void
void :: forall f a. Functor f => f a -> f UnitThe void function is used to ignore the type wrapped by a
Functor, replacing it with Unit and keeping only the type
information provided by the type constructor itself.
void is often useful when using do notation to change the return type
of a monadic computation:
main = forE 1 10 \n -> void do
print n
print (n * n)
#(<$>)
Operator alias for Data.Functor.map (left-associative / precedence 4)
#(<$)
Operator alias for Data.Functor.voidRight (left-associative / precedence 4)
#(<#>)
Operator alias for Data.Functor.mapFlipped (left-associative / precedence 1)
#($>)
Operator alias for Data.Functor.voidLeft (left-associative / precedence 4)
Modules
- Control.Alt
- Control.Alternative
- Control.Applicative
- Control.Apply
- Control.Biapplicative
- Control.Biapply
- Control.Bind
- Control.Category
- Control.Comonad
- Control.Extend
- Control.Lazy
- Control.Monad
- Control.Monad.Gen
- Control.Monad.Gen.Class
- Control.Monad.Gen.Common
- Control.Monad.Rec.Class
- Control.Monad.ST
- Control.Monad.ST.Class
- Control.Monad.ST.Global
- Control.Monad.ST.Internal
- Control.Monad.ST.Ref
- Control.MonadPlus
- Control.MonadZero
- Control.Plus
- Control.Semigroupoid
- Data.Array
- Data.Array.NonEmpty
- Data.Array.NonEmpty.Internal
- Data.Array.Partial
- Data.Array.ST
- Data.Array.ST.Iterator
- Data.Array.ST.Partial
- Data.Bifoldable
- Data.Bifunctor
- Data.Bifunctor.Clown
- Data.Bifunctor.Flip
- Data.Bifunctor.Join
- Data.Bifunctor.Joker
- Data.Bifunctor.Product
- Data.Bifunctor.Wrap
- Data.Bitraversable
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Char
- Data.Char.Gen
- Data.Char.Utils
- Data.CommutativeRing
- Data.Distributive
- Data.DivisionRing
- Data.Either
- Data.Either.Inject
- Data.Either.Nested
- Data.Enum
- Data.Enum.Gen
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Foldable
- Data.FoldableWithIndex
- Data.Function
- Data.Function.Uncurried
- Data.Functor
- Data.Functor.Invariant
- Data.FunctorWithIndex
- Data.HeytingAlgebra
- Data.Identity
- Data.Int
- Data.Int.Bits
- Data.Maybe
- Data.Maybe.First
- Data.Maybe.Last
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Alternate
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.NonEmpty
- Data.Ord
- Data.Ord.Down
- Data.Ord.Max
- Data.Ord.Min
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Foldable
- Data.Semigroup.Last
- Data.Semigroup.Traversable
- Data.Semiring
- Data.Show
- Data.String
- Data.String.CaseInsensitive
- Data.String.CodePoints
- Data.String.CodeUnits
- Data.String.Common
- Data.String.Gen
- Data.String.NonEmpty
- Data.String.NonEmpty.CaseInsensitive
- Data.String.NonEmpty.CodePoints
- Data.String.NonEmpty.CodeUnits
- Data.String.NonEmpty.Internal
- Data.String.Pattern
- Data.String.Regex
- Data.String.Regex.Flags
- Data.String.Regex.Unsafe
- Data.String.Unsafe
- Data.String.Utils
- Data.Symbol
- Data.Traversable
- Data.Traversable.Accum
- Data.Traversable.Accum.Internal
- Data.TraversableWithIndex
- Data.Tuple
- Data.Tuple.Nested
- Data.Unfoldable
- Data.Unfoldable1
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Ref
- Effect.Uncurried
- Effect.Unsafe
- Global
- Global.Unsafe
- MCPrelude
- Main
- Math
- PSCI.Support
- Partial
- Partial.Unsafe
- Prelude
- Prim
- Prim.Boolean
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Row
- Type.Data.RowList
- Type.Equality
- Unsafe.Coerce