Hoogle Search

Within LTS Haskell 24.67 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. localSeqLend :: forall (lentEs :: [Effect]) (es :: [Effect]) (handlerEs :: [Effect]) (localEs :: [Effect]) a . (HasCallStack, KnownSubset lentEs es, SharedSuffix es handlerEs) => LocalEnv localEs handlerEs -> ((forall r . () => Eff (lentEs ++ localEs) r -> Eff localEs r) -> Eff es a) -> Eff es a

    effectful-core Effectful.Dispatch.Dynamic

    Lend effects to the local environment. Consider the following effect:

    >>> :{
    data D :: Effect where
    D :: D m ()
    type instance DispatchOf D = Dynamic
    :}
    
    and an auxiliary effect that requires both IOE and D to run:
    >>> :{
    data E :: Effect
    runE :: (IOE :> es, D :> es) => Eff (E : es) a -> Eff es a
    runE = error "runE"
    :}
    
    Trying to use runE inside the handler of D doesn't work out of the box:
    >>> :{
    runD :: IOE :> es => Eff (D : es) a -> Eff es a
    runD = interpret $ \env -> \case
    D -> localSeqUnlift env $ \unlift -> do
    unlift . runE $ pure ()
    :}
    ...
    ...Could not deduce ...IOE :> localEs... arising from a use of ‘runE’
    ...from the context: IOE :> es
    ...
    
    The problem is that runE needs IOE :> localEs, but only IOE :> es is available. This function allows us to bridge the gap:
    >>> :{
    runD :: IOE :> es => Eff (D : es) a -> Eff es a
    runD = interpret $ \env -> \case
    D -> localSeqUnlift env $ \unlift -> do
    localSeqLend @'[IOE] env $ \useIOE -> do
    unlift . useIOE . runE $ pure ()
    :}
    

  2. localSeqLift :: forall (es :: [Effect]) (handlerEs :: [Effect]) (localEs :: [Effect]) a . (HasCallStack, SharedSuffix es handlerEs) => LocalEnv localEs handlerEs -> ((forall r . () => Eff es r -> Eff localEs r) -> Eff es a) -> Eff es a

    effectful-core Effectful.Dispatch.Dynamic

    Create a local lifting function with the SeqUnlift strategy. For the general version see localLift.

  3. localSeqUnlift :: forall (es :: [Effect]) (handlerEs :: [Effect]) (localEs :: [Effect]) a . (HasCallStack, SharedSuffix es handlerEs) => LocalEnv localEs handlerEs -> ((forall r . () => Eff localEs r -> Eff es r) -> Eff es a) -> Eff es a

    effectful-core Effectful.Dispatch.Dynamic

    Create a local unlifting function with the SeqUnlift strategy. For the general version see localUnlift.

  4. localSeqUnliftIO :: forall (es :: [Effect]) (handlerEs :: [Effect]) (localEs :: [Effect]) a . (HasCallStack, SharedSuffix es handlerEs, IOE :> es) => LocalEnv localEs handlerEs -> ((forall r . () => Eff localEs r -> IO r) -> IO a) -> Eff es a

    effectful-core Effectful.Dispatch.Dynamic

    Create a local unlifting function with the SeqUnlift strategy. For the general version see localUnliftIO.

  5. seqUnliftIO :: forall (es :: [Effect]) a . HasCallStack => Env es -> ((forall r . () => Eff es r -> IO r) -> IO a) -> IO a

    effectful-core Effectful.Dispatch.Static

    Create an unlifting function with the SeqUnlift strategy.

  6. unsafeSeqUnliftIO :: forall (es :: [Effect]) a . HasCallStack => ((forall r . () => Eff es r -> IO r) -> IO a) -> Eff es a

    effectful-core Effectful.Dispatch.Static

    Create an unlifting function with the SeqUnlift strategy. This function is unsafe because it can be used to introduce arbitrary IO actions into pure Eff computations.

  7. SeqForkUnlift :: UnliftStrategy

    effectful-core Effectful.Internal.Monad

    Like SeqUnlift, but all unlifted actions will be executed in a cloned environment. The main consequence is that thread local state is forked at the point of creation of the unlifting function and its modifications in unlifted actions will not affect the main thread of execution (and vice versa):

    >>> import Effectful
    
    >>> import Effectful.State.Dynamic
    
    >>> :{
    action :: (IOE :> es, State Int :> es) => Eff es ()
    action = do
    modify @Int (+1)
    withEffToIO SeqForkUnlift $ \unlift -> unlift $ modify @Int (+2)
    modify @Int (+4)
    :}
    
    >>> runEff . execStateLocal @Int 0 $ action
    5
    
    >>> runEff . execStateShared @Int 0 $ action
    7
    
    Because of this it's possible to safely use the unlifting function outside of the scope of effects it captures, e.g. by creating an IO action that executes effectful operations and running it later:
    >>> :{
    delayed :: UnliftStrategy -> IO (IO String)
    delayed strategy = runEff . evalStateLocal "Hey" $ do
    r <- withEffToIO strategy $ \unlift -> pure $ unlift get
    modify (++ "!!!")
    pure r
    :}
    
    This doesn't work with the SeqUnlift strategy because when the returned action runs, State is no longer in scope:
    >>> join $ delayed SeqUnlift
    *** Exception: version (...) /= storageVersion (0)
    ...
    
    However, it does with the SeqForkUnlift strategy:
    >>> join $ delayed SeqForkUnlift
    "Hey"
    

  8. SeqUnlift :: UnliftStrategy

    effectful-core Effectful.Internal.Monad

    The sequential strategy is the fastest and a default setting for IOE. Any attempt of calling the unlifting function in threads distinct from its creator will result in a runtime error.

  9. seqForkUnliftIO :: forall (es :: [Effect]) a . HasCallStack => Env es -> ((forall r . () => Eff es r -> IO r) -> IO a) -> IO a

    effectful-core Effectful.Internal.Monad

    Create an unlifting function with the SeqForkUnlift strategy.

  10. seqUnliftIO :: forall (es :: [Effect]) a . HasCallStack => Env es -> ((forall r . () => Eff es r -> IO r) -> IO a) -> IO a

    effectful-core Effectful.Internal.Monad

    Create an unlifting function with the SeqUnlift strategy.

Page 483 of many | Previous | Next