The strategy to use when unlifting Eff computations via withEffToIO or the localUnlift family.
Constructors
SeqUnliftThe 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.
SeqForkUnliftLike 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):
Example3 expressions import Effectfulimport 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):}
Example1 expression runEff . execStateLocal @Int 0 $ action5
Example1 expression runEff . execStateShared @Int 0 $ action7
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
IOaction that executes effectful operations and running it later:Example1 expression :{ 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,
Stateis no longer in scope:Example1 expression join $ delayed SeqUnlift*** Exception: version (...) /= storageVersion (0)...
However, it does with the SeqForkUnlift strategy:
Example1 expression join $ delayed SeqForkUnlift"Hey"
ConcUnlift !Persistence !LimitThe concurrent strategy makes it possible for the unlifting function to be called in threads distinct from its creator. See Persistence and Limit settings for more information.
Instances5Eq, Ord, Show, Generic, Rep
Eq UnliftStrategyDefined in effectful-core-2.7.1.2 · Effectful.Internal.UnliftOrd UnliftStrategyDefined in effectful-core-2.7.1.2 · Effectful.Internal.UnliftShow UnliftStrategyDefined in effectful-core-2.7.1.2 · Effectful.Internal.UnliftGeneric UnliftStrategyDefined in effectful-core-2.7.1.2 · Effectful.Internal.Unlifttype Rep UnliftStrategy = D1 ('MetaDataDefined in effectful-core-2.7.1.2 · Effectful.Internal.Unlift"UnliftStrategy"
"Effectful.Internal.Unlift"
"effectful-core-2.7.1.2-1tMrgZZW0TYLqA0MoiOzOF"
'False) (C1 ('MetaCons"SeqUnlift"
'PrefixI 'False) U1 :+: (C1 ('MetaCons"SeqForkUnlift"
'PrefixI 'False) U1 :+: C1 ('MetaCons"ConcUnlift"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Persistence) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Limit))))