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!
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
evalStateenforces that there are no existing higher order effects in the stack:runCatchandrunThrowhave similar constraints.On the other hand,
runReaderhas a much more permissive type:What confuses me more is that
runStateIORefalso has the permissive constraints: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
runStateIORefhas 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!