Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ExceptT ResourceT' vs 'ResourceT ExceptT'

Real World Haskell states that "Transformer stacking order is important". However, I can't seem to figure out if there's a difference between ExceptT (ResourceT m) a and ResourceT (ExceptT m) a. Will they interfere with each other?

like image 322
Dan Avatar asked Sep 25 '22 21:09

Dan


1 Answers

In this example, there is no real difference between both orders. The reason being: unlike many transformers including ExceptT, the resource transformer does not “inject” its own doings into the base monad you apply it to, but rather start off the entire action with passing in the release references.

If you write out the types (I'll refer to MaybeT instead of ExceptT for the sake of simplicity; they're obviously equivalent for the purpose of this question) then you have basically

type MaybeResourceT m a = MaybeT (IORef RelMap -> m a)
                        = IORef RelMap -> m (Maybe a)
type ResourceMaybeT m a = ResourceT (m (Maybe a))
                        = IORef RelMap -> m (Maybe a)

i.e. actually equivalent types. I suppose you could also show that for the operations.

like image 110
leftaroundabout Avatar answered Nov 15 '22 09:11

leftaroundabout