Monad transformers are tricky, and I'm not sure (= don't have good intuition) which one should go on top.
StateT s (ExceptT e m)
This says:
m
Now, 'adding exceptions' means your actions can terminate in two ways: either with a normal return value, or with an exception.
'Adding state' means that an extra bit of state output gets included in the normal return values.
So in StateT s (ExceptT e m), you only get a result state if there is no exception.
On the other hand,
ExceptT e (StateT s m)
says:
m
'Adding state' means that an extra bit of state output gets included in the return values of m.
But now, your added exceptions get added as an alternative return value inside the StateT monad. So you always get a state output, and then you may get a normal return value or you may get an exception along with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With