by tom_mellior · 8y ago · 0 comments
Also, what would the print call really look like in actual code? This post talks about composing IO with other monads. I've never seen a monad composition example that wasn't peppered with calls to unintuitively named functions like liftM_.
The pseudocode looks nice, but if the pseudocode isn't a faithful representation of actual use, then it's not very useful.
I’m on mobile, otherwise this would’ve been an answer instead of a comment.
(Abstract in this way, in this kind of context...)
Maybe is a Monad. In Haskell, Monad is sort of like an interface (called typeclass) that a bunch of types implement. Maybe has an instance of Monad already, same with lists, and continuations, etc.
It's moving code more towards "this is what I want" rather than "here's how to do what I want".
In languages that have no access to the monad abstraction you'll still need a way to replace your database access with something that you can use during your testing. A monadic database interface won't save you from having to check that your application doesn't do silly things with the database as a side-effect, but it will make it much easier to test that your actual data processing is correct.
You will need to convert your type into something else to use in another monad.
As an example, it's common to track failure with an `Either Text` monad, but functions that can fail on a single way usually have an `Maybe a` return type. That means you will probably have an `Text -> Maybe a -> Either Text a` function around and write code like this:
toEither "Error message" $ functionInMaybe a bAnd the monad interface doesn't help us with that. But the answer is that you have a Maybe, you can do any Maybe thing with it.