[Haskell-beginners] Can I lift this interestingly typed function into a Maybe?

Simon Peter Nicholls simon at mintsource.org
Thu Jan 24 15:56:47 CET 2013


Hi all,

My issue is generic Haskell use, but I should provide the specific
background. I have some Snap code:

    eres <- eitherWithDB $ DB.findOne (DB.select [] "someCollection")
    let maybeVal = either (error "Mongoed") (maybe Nothing fromBson) eres

and this works so that "maybeVal" will be of type Maybe MyType. "eres" is
either a MongoDB Failure, or a Maybe Document (I find one document, or not).

I'd like to convert this Maybe Document to a Maybe MyType without unpacking
and repacking the Maybe. Is this possible?

The fromBson function, that converts from a Document to an end user type,
confuses me due to it's type:

    fromBson ::
Monad<http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Control-Monad.html#t:Monad>
m
=> Document<http://hackage.haskell.org/packages/archive/bson/0.1.7/doc/html/Data-Bson.html#t:Document>
->
m a


Thanks,
Si
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130124/9f21e3af/attachment.htm>


More information about the Beginners mailing list