Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6763421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:28:26+00:00 2026-05-26T14:28:26+00:00

So, the idea is that I would take the following code used to run

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:28:27+00:00Added an answer on May 26, 2026 at 2:28 pm

    I always feel like answering these questions “this is because your type is ambiguous”. For example, if you were given a value:

    MonadIO m => (Action m a -> m (Either Failure a))
    

    And told the monad m is a particular monad (not just any one), can you tell which one it is? No.

    If you don’t use the returned value in a context that makes it apparent to which Monad m belongs, then you need to give the compiler additional information:

    db <- connectDB "127.0.0.1" "testdb" :: IO (Action IO a -> IO (Either Failure a))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a piece of code that will do the following: Take
I had an idea that would require me be able to send and receive
I am playing with an idea that would allow people to add tickets to
Someone once showed me a cool IntelliJ Idea plugin that would show all the
I had the idea of a search engine that would index web items like
I am looking for an idea, concept or proven datastructure that would be very
I have an idea for an app that I would like to build which
I would like to use conditions in my CSS. The idea is that I
For example take the following class: class GameBoard { public double Evaluate(PieceType cpusPieceType) {
Please take a look on the following pseudo-code: boolean blocked[2]; int turn; void P(int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.