Module

Effect.Unlift

Package
purescript-unlift
Repository
tweag/purescript-unlift

#MonadUnliftEffect Source

class MonadUnliftEffect :: (Type -> Type) -> Constraintclass (MonadEffect m) <= MonadUnliftEffect m  where

Monads which allow their actions to be run in Effect.

MonadUnliftEffect captures the opposite notion of MonadEffect - while MonadEffect allows an Effect to be lifted into another monad, MonadUnliftEffect allows a monad other than Effect to be run in an Effect context.

Note that the laws given below require that a monad have no "monadic state", which essentially limits instances to ReaderT and IdentityT stacks with a base of Effect.

Instances should satisfy the following laws, which state that unliftEffect is a transformer of monads for any given u returned by askUnliftEffect:

unliftEffect u <<< pure = pure
unliftEffect u (f =<< m) = unliftEffect u <<< f =<< unliftEffect u m

Members

  • withRunInEffect :: forall b. ((m ~> Effect) -> Effect b) -> m b

    Run an Effect with access to a runner function that is capable of running a monadic action m in Effect.

Instances

#UnliftEffect Source

newtype UnliftEffect :: (Type -> Type) -> Typenewtype UnliftEffect m

A newtype wrapper around a natural transformation from m to Effect.

Constructors

#unliftEffect Source

unliftEffect :: forall m. UnliftEffect m -> m ~> Effect

Run an action directly in Effect. Use askUnliftEffect or withUnliftEffect to obtain an UnliftEffect m value.

#askUnliftEffect Source

askUnliftEffect :: forall m. MonadUnliftEffect m => m (UnliftEffect m)

Returns a natural transformation from m to Effect within an m context. This can subsequently be used to run m actions directly in Effect.

#askRunInEffect Source

askRunInEffect :: forall m a. MonadUnliftEffect m => m (m a -> Effect a)

A monomorphic version of askUnliftEffect which can be more convenient when you only want to use the resulting runner function once with a concrete type.

If you run into type issues using this, try using askUnlitEffect instead.

#withUnliftEffect Source

withUnliftEffect :: forall m a. MonadUnliftEffect m => (UnliftEffect m -> Effect a) -> m a

A version of withRunInEffect that provides an UnliftEffect wrapper instead of a rank-2 polymorphic function.

#toEffect Source

toEffect :: forall m a. MonadUnliftEffect m => m a -> m (Effect a)

Run the given action inside the Effect monad.