Discussion:
Extending ServerPartT
Lambda Dusk
2012-04-01 08:58:11 UTC
Permalink
Hi,

I am new to Happstack. Not so new to Haskell, but I have always had a big
trouble designing monadic data types. It always seems simple, but I have
some kind of mind block there.

I have some server settings (for now, a database connection pool), and I
want to put them into a ReaderT monad, that is then wrapped in the
ServerPartT. Specifically, I have these two functions:

withMongo :: (MongoPool -> IO a) -> IO ()
withMongo f = do
pool <- dbPool
f pool
killAll pool

runDB :: (MonadIO m) => MongoPool -> Action IO a -> m (Either Failure a)
runDB pool f = liftIO $ do
pipe <- runIOE $ aResource pool
access pipe master dbName f

I would love to change "withMongo" in a way that I can drop it in before my
"simpleHTTP" call. The type of runDB could be something like "Action IO a
-> ServerPartT m (Either Failure a)" so it can be used in any handler
without having to carry the pool with me all the time.

I know this is not exactly a Happstack question, but I'd thought the
chances are high someone on here has already done this specifically.

Thanks.
--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/happs/-/cAJ2wiO-VgEJ.
To post to this group, send email to happs-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to happs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/happs?hl=en.
MightyByte
2012-04-01 16:43:14 UTC
Permalink
Hi,

We have a solution for exactly this problem in the Snap Framework.
It's called snaplets and it makes it really easy to do what you're
talking about. In fact, there are already two different snaplets
available on hackage that provide MongoDB support, so you probably
wouldn't even need to do it yourself. Snap's low-level API is very
similar to that of Happstack, so you shouldn't have too much trouble
converting if you already have code.
Post by Lambda Dusk
Hi,
I am new to Happstack. Not so new to Haskell, but I have always had a big
trouble designing monadic data types. It always seems simple, but I have
some kind of mind block there.
I have some server settings (for now, a database connection pool), and I
want to put them into a ReaderT monad, that is then wrapped in the
withMongo :: (MongoPool -> IO a) -> IO ()
withMongo f = do
pool <- dbPool
f pool
killAll pool
runDB :: (MonadIO m) => MongoPool -> Action IO a -> m (Either Failure a)
runDB pool f = liftIO $ do
pipe <- runIOE $ aResource pool
access pipe master dbName f
I would love to change "withMongo" in a way that I can drop it in before my
"simpleHTTP" call. The type of runDB could be something like "Action IO a ->
ServerPartT m (Either Failure a)" so it can be used in any handler without
having to carry the pool with me all the time.
I know this is not exactly a Happstack question, but I'd thought the chances
are high someone on here has already done this specifically.
Thanks.
--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/happs/-/cAJ2wiO-VgEJ.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/happs?hl=en.
--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To post to this group, send email to happs-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to happs+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/happs?hl=en.
Loading...