Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stacking ResourceT monad transformer

I'd like to stack ResourceT with the ReaderT monad. It seems I have two options: Either place ReaderT on the bottom or at the top of the stack.

data MyEnv

newtype MyT1 m a = MyT1 { unT1 :: ResourceT (ReaderT MyEnv m) a }

newtype MyT2 m a = MyT2 { unT2 :: ReaderT MyEnv (ResourceT m) a }

What would be better in sence of performance/correctness? What are the general guidelines for stacking ResourceT with WriterT or other monads?

like image 466
schernichkin Avatar asked Mar 18 '14 01:03

schernichkin


1 Answers

As far as correctness goes, they are both equally correct -- see comments by @J.Abrahamson and @Michael Snoyman.

Performance probably depends on use, in particular it will change how many calls to lift cross that particular layer, which should be the main performance difference. I'd imagine most fair benchmarks would show little to no difference. For whole program performance, profiling is king.

like image 130
Boyd Stephen Smith Jr. Avatar answered Nov 09 '22 11:11

Boyd Stephen Smith Jr.