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