| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Bluefin.Internal.GadtEffect
Synopsis
- newtype Send (f :: Effect) (e :: Effects) = MkSend (EffectHandler f e)
- type Effect = (Type -> Type) -> Type -> Type
- send :: forall (e1 :: Effects) (es :: Effects) f r. e1 :> es => Send f e1 -> f (Eff es) r -> Eff es r
- type EffectHandler (f :: (Type -> Type) -> Type -> Type) (es :: Effects) = forall (e :: Effects) r. f (Eff e) r -> Eff (e :& es) r
- interpret :: forall (f :: (Type -> Type) -> Type -> Type) (es :: Effects) r. EffectHandler f es -> (forall (e :: Effects). Send f e -> Eff (e :& es) r) -> Eff es r
- newtype GadtEffect (f :: (Type -> Type) -> Type -> Type) a (e :: Effects) = MkGadtEffect {
- unGadtEffect :: f (Eff e) a
- mapGadtEffect :: forall f1 (e1 :: Effects) r1 f2 (e2 :: Effects) r2. (f1 (Eff e1) r1 -> f2 (Eff e2) r2) -> GadtEffect f1 r1 e1 -> GadtEffect f2 r2 e2
- oneWayCoercibleGadtEffectTrustMe :: forall (e :: Effects) (es :: Effects) f r. e :> es => (forall (e' :: Effects) (es' :: Effects). e' :> es' => f (Eff e') r -> f (Eff es') r) -> OneWayCoercibleD (GadtEffect f r e) (GadtEffect f r es)
- passthrough :: forall f r (e1 :: Effects) (es :: Effects) (e2 :: Effects). (Handle (GadtEffect f r), e1 :> es, e2 :> es) => Send f e1 -> f (Eff e2) r -> Eff es r
- interpose :: forall (e1 :: Effects) (es :: Effects) (f :: Effect) r. e1 :> es => (Send f es -> EffectHandler f es) -> HandleReader (Send f) e1 -> Eff es r -> Eff es r
Documentation
newtype Send (f :: Effect) (e :: Effects) Source #
Constructors
| MkSend (EffectHandler f e) |
Instances
| e :> es => OneWayCoercible (Send f e :: Type) (Send f es :: Type) Source # | |
Defined in Bluefin.Internal.GadtEffect Methods oneWayCoercibleImpl :: OneWayCoercibleD (Send f e) (Send f es) Source # | |
| Handle (Send f) Source # | |
Defined in Bluefin.Internal.GadtEffect Methods handleImpl :: HandleD (Send f) Source # | |
type EffectHandler (f :: (Type -> Type) -> Type -> Type) (es :: Effects) Source #
A convenient type synonym. This is like effectful's
EffectHandler.
A similar type also appears in polysemy as the argument to
functions like
intercept.
Arguments
| :: forall (f :: (Type -> Type) -> Type -> Type) (es :: Effects) r. EffectHandler f es | Implementation of effect handler for |
| -> (forall (e :: Effects). Send f e -> Eff (e :& es) r) | Within this block, |
| -> Eff es r |
import System.IO qualified as IO runFileSystem :: forall es e1 e2 r. (e1 :> es, e2 :> es) =>IOEe1 ->ExceptionIOExceptione2 -> (forall e.SendFileSystem e -> Eff (e :& es) r) -> Eff es r runFileSystem io ex =interpret$ \case ReadFile path -> adapt (IO.readFilepath) WriteFile path contents -> adapt (IO.writeFilepath contents) Trace msg body -> doeffIOio (putStrLn ("Start: " <> msg)) r <-useImplbody effIO io (putStrLn ("End: " <> msg)) pure r where -- If you don't want to write this signature you can use -- {-# LANGUAGE NoMonoLocalBinds #-} adapt :: (e1 :> es', e2 :> es') => IO r' -> Eff es' r' adapt m =rethrowIOio ex (effIO io m)
newtype GadtEffect (f :: (Type -> Type) -> Type -> Type) a (e :: Effects) Source #
Constructors
| MkGadtEffect | |
Fields
| |
mapGadtEffect :: forall f1 (e1 :: Effects) r1 f2 (e2 :: Effects) r2. (f1 (Eff e1) r1 -> f2 (Eff e2) r2) -> GadtEffect f1 r1 e1 -> GadtEffect f2 r2 e2 Source #
oneWayCoercibleGadtEffectTrustMe Source #
Arguments
| :: forall (e :: Effects) (es :: Effects) f r. e :> es | |
| => (forall (e' :: Effects) (es' :: Effects). e' :> es' => f (Eff e') r -> f (Eff es') r) | |
| -> OneWayCoercibleD (GadtEffect f r e) (GadtEffect f r es) | ͘ |
instance (e :> es) =>OneWayCoercible(GadtEffectFileSystem r e) (GadtEffect FileSystem r es) whereoneWayCoercibleImpl=oneWayCoercibleGadtEffectTrustMe$ \case ReadFile path -> ReadFile path WriteFile path contents -> WriteFile path contents Trace msg body -> Trace msg (useImpl body)
Arguments
| :: forall f r (e1 :: Effects) (es :: Effects) (e2 :: Effects). (Handle (GadtEffect f r), e1 :> es, e2 :> es) | |
| => Send f e1 | |
| -> f (Eff e2) r | |
| -> Eff es r | ͘ |
Version of send for use when pattern matching in interpose
augmentOp2Interpose :: (e1 :> es, e2 :> es) => IOE e2 ->HandleReader(Send E) e1 -> Eff es r -> Eff es r augmentOp2Interpose io =interpose$ \fc -> \case Op2 -> effIO io (putStrLn "augmented op2") >> send fc Op2 op ->passthroughfc op
Arguments
| :: forall (e1 :: Effects) (es :: Effects) (f :: Effect) r. e1 :> es | |
| => (Send f es -> EffectHandler f es) | Reimplementation of effect handler for |
| -> HandleReader (Send f) e1 | Original effect handler |
| -> Eff es r | Within this block, |
| -> Eff es r |
augmentOp2Interpose :: (e1 :> es, e2 :> es) => IOE e2 ->HandleReader(Send E) e1 -> Eff es r -> Eff es r augmentOp2Interpose io =interpose$ \fc -> \case Op2 -> effIO io (putStrLn "augmented op2") >> send fc Op2 op ->passthroughfc op