Search results

The Monad type class combines the operations of the Bind and Applicative type classes. Therefore, Monad instances represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.

Instances must satisfy the following laws in addition to the Applicative and Bind laws:

  • Left Identity: pure x >>= f = f x
  • Right Identity: x >>= pure = x
P purescript-prelude M Control.Monad
P purescript-subcategory M Control.Subcategory.Endofunctor.Monad
P purescript-subcategory M Control.Subcategory.Endofunctor.Monad
P purescript-optparse M Options.Applicative.Internal
P purescript-prelude M Control.Monad
P purescript-st M Control.Monad.ST.Class
P purescript-st M Control.Monad.ST.Internal
P purescript-pairing M Data.Functor.Pairing.Co
P purescript-open-pairing M Data.Functor.Pairing.Co
P purescript-css-class-name-extractor M CssClassNameExtractor.FS

This type class captures those monads which support tail recursion in constant stack space.

The tailRecM function takes a step function, and applies that step function recursively until a pure value of type b is found.

Instances are provided for standard monad transformers.

For example:

loopWriter :: Int -> WriterT (Additive Int) Effect Unit
loopWriter n = tailRecM go n
  where
  go 0 = do
    traceM "Done!"
    pure (Done unit)
  go i = do
    tell $ Additive i
    pure (Loop (i - 1))
P purescript-tailrec M Control.Monad.Rec.Class

A class for random generator implementations.

Instances should provide implementations for the generation functions that return choices with uniform probability.

See also Gen in purescript-quickcheck, which implements this type class.

P purescript-gen M Control.Monad.Gen.Class

The MonadAsk type class represents those monads which support a global context that can be provided via the ask function.

An implementation is provided for ReaderT, and for other monad transformers defined in this library.

Law:

  • do { ask ; ask } = ask
P purescript-transformers M Control.Monad.Reader.Class
P purescript-functors M Data.Functor.App
P purescript-aff M Effect.Aff
P purescript-aff M Effect.Aff.Class
P purescript-quickcheck M Test.QuickCheck.Gen
P purescript-run M Run
P purescript-sized-vectors M Data.Vec
P purescript-sequences M Data.Sequence
P purescript-sequences M Data.Sequence.NonEmpty
P purescript-echarts M ECharts.Monad

Type class for monads that support fixpoints.

mfix f runs f once with the eventual result of f as input. Make sure not to apply the supplied function until the computation returned; else a dynamic error will be thrown.

P purescript-concur-core M Control.MonadFix
P purescript-day M Data.Functor.Day.Hom
P purescript-hareactive M Hareactive.Types
P purescript-transformerless M Control.Monad.Transformerless.RWS
P purescript-pointed M Data.Pointed.Can

A "type class alias" for the constraints required by most FRP primitives.

P purescript-specular M Specular.FRP.Base
P purescript-specular M Specular.FRP.Base
P purescript-jack M Jack.Gen
P purescript-whine-core M Whine.Log
P purescript-css-class-name-extractor M CssClassNameExtractor.RIO
P purescript-specular M Specular.Internal.RIO
P purescript-bound M Bound
P purescript-prelude M Data.Monoid.Conj
P purescript-prelude M Data.Monoid.Disj
P purescript-prelude M Data.Monoid.Dual
P purescript-prelude M Data.Semigroup.Last

The MonadPlus type class has no members of its own; it just specifies that the type has both Monad and Alternative instances.

Types which have MonadPlus instances should also satisfy the following law:

  • Distributivity: (x <|> y) >>= f == (x >>= f) <|> (y >>= f)
P purescript-control M Control.MonadPlus
P purescript-maybe M Data.Maybe.Last
P purescript-st M Control.Monad.ST.Class
P purescript-lazy M Data.Lazy
P purescript-lists M Data.List.Lazy.Types
P purescript-lists M Data.List.Types

The MonadCont type class represents those monads which support the callCC, or call-with-current-continuation operation.

This action makes the current continuation available to the caller.

For example:

-- setTimeout :: Number -> Effect Unit -> Effect Unit

delay :: Number -> ContT Unit Effect Unit
delay n = callCC \cont ->
  lift $ setTimeout n (runContT (cont unit) (\_ -> pure unit))

An implementation is provided for ContT, and for other monad transformers defined in this library.

P purescript-transformers M Control.Monad.Cont.Class
P purescript-transformers M Control.Monad.RWS.Trans

The MonadTell w type class represents those monads which support a monoidal accumulator of type w, where tell appends a value to the accumulator.

An implementation is provided for WriterT, and for other monad transformers defined in this library.

Law:

  • do { tell x ; tell y } = tell (x <> y)
P purescript-transformers M Control.Monad.Writer.Class
P purescript-profunctor M Data.Profunctor.Star

Based on http://hackage.haskell.org/package/free/docs/Control-Monad-Free-Class.html

P purescript-free M Control.Monad.Free.Class

Represents Monads which can be forked asynchronously.

Laws:

-- Unjoined suspension is a no-op
suspend a1 *> suspend a2 = suspend a2

-- Suspend/join is identity
suspend >=> join = id

-- Fork/join is identity
fork >=> join = id

-- Join is idempotent
join t *> join t = join t
P purescript-fork M Control.Monad.Fork.Class

Represents Monads which can be killed after being forked.

Laws:

-- Killed suspension is an exception
suspend a >>= \f -> kill e f *> join f = throwError e

-- Suspend/kill is unit
suspend a >>= kill e = pure unit
P purescript-fork M Control.Monad.Fork.Class
P purescript-machines M Data.Machine.Mealy
P purescript-monad-control M Control.Monad.Base
P purescript-express M Node.Express.App
P purescript-probability M Math.Probability.Dist.Internal
P purescript-pairs M Data.Pair
P purescript-web3 M Network.Ethereum.Web3.Types.Types
P purescript-transformerless M Control.Monad.Transformerless.Cont
P purescript-distributions M Data.Distribution
P purescript-react-ix M React.Ix.EffR
P purescript-periodic M Periodic.Worker
P purescript-rrb-list M RRBList.Types
P purescript-bucketchain-simple-api M Bucketchain.SimpleAPI.Proc
P purescript-redux-saga M Redux.Saga
P purescript-task M Task
P purescript-task M Task.Class
P purescript-jack M Jack.Tree
P purescript-rx M Rx.Observable
P purescript-prelude M Control.Monad
P purescript-prelude M Data.Semigroup.First
P purescript-prelude M Control.Monad
P purescript-maybe M Data.Maybe.First

The Monad instance guarantees that there are both Applicative and Bind instances for Maybe. This also enables the do syntactic sugar:

do
  x' <- x
  y' <- y
  pure (f x' y')

Which is equivalent to:

x >>= (\x' -> y >>= (\y' -> pure (f x' y')))

Which is equivalent to:

case x of
  Nothing -> Nothing
  Just x' -> case y of
    Nothing -> Nothing
    Just y' -> Just (f x' y')
P purescript-maybe M Data.Maybe
P purescript-tuples M Data.Tuple
P purescript-st M Control.Monad.ST.Internal
P purescript-transformers M Control.Monad.Cont.Trans

The MonadError type class represents those monads which support catching errors.

  • catchError x f calls the error handler f if an error is thrown during the evaluation of x.

An implementation is provided for ExceptT, and for other monad transformers defined in this library.

Laws:

  • Catch: catchError (throwError e) f = f e
  • Pure: catchError (pure a) f = pure a
P purescript-transformers M Control.Monad.Error.Class
P purescript-transformers M Control.Monad.List.Trans

The MonadState s type class represents those monads which support a single piece of mutable state of type s.

  • state f updates the state using the function f.

An implementation is provided for StateT, and for other monad transformers defined in this library.

Laws:

  • do { get ; get } = get
  • do { put x ; put y } = put y
  • do { put x ; get } = put x $> x
  • do { s <- get ; put s } = pure unit
P purescript-transformers M Control.Monad.State.Class

The MonadThrow type class represents those monads which support errors via throwError, where throwError e halts, yielding the error e.

An implementation is provided for ExceptT, and for other monad transformers defined in this library.

Laws:

  • Left zero: throwError e >>= f = throwError e
P purescript-transformers M Control.Monad.Error.Class

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.

Laws:

  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }
P purescript-transformers M Control.Monad.Trans.Class
P purescript-functors M Data.Functor.Joker
P purescript-aff M Effect.Aff
P purescript-pipes M Pipes.Internal
P purescript-spec M Test.Spec
P purescript-freet M Control.Monad.Free.Trans
P purescript-these M Data.These
P purescript-machines M Data.Machine.Mealy
P purescript-errors M Data.EitherR
P purescript-pairing M Data.Functor.Pairing.Co
P purescript-jelly-signal M Jelly.Hooks
P purescript-day M Data.Functor.Day.Hom

This class is for Monads whose side effect includes delayed computation. So far, it's Effect and Hooks.

P purescript-reactix M Reactix.React
P purescript-reactix M Reactix.React
P purescript-channel M Concurrent.Channel
P purescript-transformerless M Control.Monad.Transformerless.State
P purescript-open-pairing M Data.Functor.Pairing.Co
P purescript-webdriver M Selenium.Builder
P purescript-debugger M Debug
P purescript-emo8 M Emo8.Data.Draw