HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleeffectful-core-2.3.0.1Haskell2010

Effectful.Provider

Turn an effect handler into an effectful operation.

  • 2 types
  • 6 values

Example

0 declarations
Example4 expressions
import Control.Monad.IO.Classimport Effectful.Dispatch.Dynamicimport Effectful.State.Static.Localimport qualified Data.Map.Strict as M

Given an effect:

Example1 expression
:{  data Write :: Effect where    Write :: String -> Write m ()  type instance DispatchOf Write = Dynamic:}
Example1 expression
:{  write :: Write :> es => String -> Eff es ()  write = send . Write:}

its handler can be turned into an effectful operation with the Provider effect:

Example1 expression
:{  action :: Provider_ Write FilePath :> es => Eff es ()  action = do    provideWith_ @Write "in.txt" $ do      write "hi"      write "there"    provideWith_ @Write "out.txt" $ do      write "good"      write "bye":}

Then, given multiple interpreters:

Example1 expression
:{  runWriteIO    :: IOE :> es    => FilePath    -> Eff (Write : es) a    -> Eff es a  runWriteIO fp = interpret $ \_ -> \case    Write msg -> liftIO . putStrLn $ fp ++ ": " ++ msg:}
Example1 expression
:{  runWritePure    :: State (M.Map FilePath [String]) :> es    => FilePath    -> Eff (Write : es) a    -> Eff es a  runWritePure fp = interpret $ \_ -> \case    Write msg -> modify $ M.insertWith (++) fp [msg]:}

action can be supplied with either of them for the appropriate behavior:

Example1 expression
:{  runEff    . runProvider_ runWriteIO    $ action:}in.txt: hiin.txt: thereout.txt: goodout.txt: bye
Example1 expression
:{  runPureEff    . fmap (fmap reverse)    . execState @(M.Map FilePath [String]) M.empty    . runProvider_ runWritePure    $ action:}fromList [("in.txt",["hi","there"]),("out.txt",["good","bye"])]

Effect

2 declarations
datadata Provider (e :: Effect) input (f :: Type -> Type) (a :: Type -> Type) b
#

Provide a way to run a handler of e with a given input.

Note: f can be used to alter the return type of the effect handler. If that's unnecessary, use Provider_.

Instances2DispatchOf, StaticRep
  • type DispatchOf (Provider e input f) = 'Static 'NoSideEffectsDefined in effectful-core-2.3.0.1 · Effectful.Provider
  • data StaticRep (Provider e input f)
    • Provider :: !Env handlerEs -> !(forall r. input -> Eff (e ': handlerEs) r -> Eff handlerEs (f r)) -> R:StaticRepProvider e input f
    Defined in effectful-core-2.3.0.1 · Effectful.Provider

Handlers

valuerunProvider_
  1. :: (forall r. input -> Eff (e ': es) r -> Eff es r)

    The effect handler.

  2. -> Eff (Provider_ e input ': es) a
  3. -> Eff es a
#

Run the Provider effect with a given effect handler that doesn't change its return type.

Operations

valueprovideWith
  1. :: Provider e input f :> es
  2. => input

    The input to the effect handler.

  3. -> Eff (e ': es) a
  4. -> Eff es (f a)
#

Run the effect handler with a given input.

valueprovideWith_
  1. :: Provider_ e input :> es
  2. => input

    The input to the effect handler.

  3. -> Eff (e ': es) a
  4. -> Eff es a
#

Run the effect handler that doesn't change its return type with a given input.