MonadBaseControl IO instance for Handlers

24 views
Skip to first unread message

Dmitry Dzhus

unread,
Feb 5, 2012, 4:45:13 AM2/5/12
to sn...@snapframework.com
How are you gentlemen?

I'd like to switch to using Pool from resource-pool [1] package in my
snaplet [2] to handle database connection pool. This requires my
Handlers to have MonadBaseControl IO instance, whereas Snap provides
MonadCatchIO. Seems like using resource-pool-catchio fork [3] could do
the trick, but is there any chance to see MonadBaseControl support in
Snap?

[1]: http://hackage.haskell.org/package/resource-pool
[2]: https://github.com/dzhus/snap-redis-crud/blob/master/src/RedisDB.hs
[3]: http://hackage.haskell.org/package/resource-pool-catchio

Gregory Collins

unread,
Feb 5, 2012, 5:46:08 AM2/5/12
to Dmitry Dzhus, sn...@snapframework.com, Jasper Van der Jeugt, j.stut...@me.com
I think one of Jurriën or Jasper was working on it, but it's actually not easy to do; there are little wrinkles in our MonadCatchIO instance which MonadBaseControl doesn't support. You're better off just lifting to IO and running your database code there.

G
-- 
Gregory Collins <gr...@gregorycollins.net>

Jurriën Stutterheim

unread,
Feb 5, 2012, 9:11:33 AM2/5/12
to Gregory Collins, Dmitry Dzhus, sn...@snapframework.com, Jasper Van der Jeugt
I've made an attempt to port Snap to monad-control, but it broke the entire framework in non-obvious ways. It is possible to define a `MonadControlIO` instance for `Handler`, though (monad-control-0.2.x). That would allow you to use the original resource-pool. I didn't get around to writing instances for the latest version of monad-control though (I decided to switch back to `MonadCatchIO` instead). Here's the code I had for `MonadControlIO`:

#if MIN_VERSION_monad_control(0,3,0)

#else
instance MonadControlIO (Handler b v) where
liftControlIO f = liftBase (f return)
#endif


Jurriën

Reply all
Reply to author
Forward
0 new messages