2
votes

In Database.MongoDB.Query, there is this function:

access :: MonadIO m => Pipe -> AccessMode -> Database -> Action m a -> m a

The documentation says this about the function:

Run action against database on server at other end of pipe. Use access mode for any reads and writes. Return Left on connection failure or read/write failure.

  • What does "return Left" mean here? I ask because m can be any monad (with a MonadIO instance). For instance, what does "return Left" mean if m is just the IO monad?
  • Must m be the Either monad for me to be able to detect connection or read/write failure when using the access method?
1
The actual code simply throws exceptions in case of error - I'm guessing that "return Left" is just a typo or a remnant from a time when the return type was different. "return Left" is indeed completely nonsense when working with IO or MonadIO m (I suppose it makes sense if you had e.g. IO (Either a b) ). Furthermore, Either cannot be an instance of MonadIO so you can't even instantiate m with Either. Although, MonadIO m => EitherT e m has an instance, but even if you use this instantiation, you will never get Left something from access - it's type even guarantees this.user2407038
here is an old version in which the return type is m (Either Failure a) - it does really seem like just a case of outdated documentation. (If it's important to you, you should contact the maintainer)user2407038
Here`s probably a good place to report that - or you could even make a pull request by clicking on the pencil icon here to do the work for him.Gurkenglas
@user2407038 That's an answer, not a comment!Daniel Wagner
@user2407038 Write this into an answer please so I can accept it :)haskellHQ

1 Answers

1
votes

Yes. It's a type. Return Left comes from an older version. If any errors happens then it just throws IO exceptions. We'll need to fix it. I filed a bug for it. https://github.com/mongodb-haskell/mongodb/issues/67