Skip to content

Interpreters forcing empty effect lists #21

Description

@Burtannia

I've been experimenting with heftia a bit and noticed that the types of various interpreters force certain constraints on interpretation order. For example, the following evalState enforces that there are no existing higher order effects in the stack:

evalState :: forall s (ef :: [Type -> Type]) a. s -> Eff ('[] :: [EffectH]) (State s ': ef) a -> Eff ('[] :: [EffectH]) ef a

runCatch and runThrow have similar constraints.

On the other hand, runReader has a much more permissive type:

runReader :: forall r (eh :: [(Type -> Type) -> Type -> Type]) (ef :: [Type -> Type]). r -> Eff (Local r ': eh) (Ask r ': ef) ~> Eff eh ef

What confuses me more is that runStateIORef also has the permissive constraints:

runStateIORef :: forall s (ef :: [EffectF]) (eh :: [EffectH]) a. IO <| ef => s -> Eff eh (State s ': ef) a -> Eff eh ef (s, a)

What's the reason for these constraints? I'd assumed it was to prevent the footgun of interpreting effects in the wrong order and accidentally letting exceptions through. But then I'm confused as to why runStateIORef has the more permissive constraint? Or is it due to using an IORef, we get atomic state updates so can be more permissive than pure state?

If this is the case then I think that's a feature that needs to be stated more clearly, because, despite being a little confusing to new-comers, it's fantastic!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions