So, the idea is that I would take the following code used to run MongoDB queries in haskell
- Full Example: https://gist.github.com/1337864
Intro to Haskell MongoDB Driver: https://github.com/TonyGen/mongoDB-haskell/blob/master/doc/Example.hs
pipe <- runIOE $ connect $ host "127.0.0.1" let run action = access pipe master "testdb" action run $ delete $ select [] "mycollection"
And I would like to turn it into this, so that I can pretend that the run function is a "db", like in the normal mongo driver.
db <- connectDb "127.0.0.1" "testdb"
db $ delete $ select [] "mycollection"
Here's the function I wrote to do it:
mdb :: (MonadIO m) => String -> String -> IO (Action m a -> m (Either Failure a))
mdb hostname dbname = do
pipe <- runIOE $ connect $ host hostname
return (access pipe master (pack dbname))
I got the type by leaving it untyped, then asking ghci what the type was. I barely understand it.
So here's the question
When I make my program have ONLY db <- connectDb "127.0.0.1" "testdb" and don't use it, it fails with this Ambiguous Type error: https://gist.github.com/1337864 - How can I make it unambiguous? Is it a bad idea to make this kind of an abstraction? How would you do it?