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.
It's moving code more towards "this is what I want" rather than "here's how to do what I want".
I’m on mobile, otherwise this would’ve been an answer instead of a comment.
(Abstract in this way, in this kind of context...)
And 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.
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 bMaybe 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.
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.
Secondarily, I wish “monads are cool” tutorials would pay some attention on how the do syntax interacts with the rest of the language, and especially with conditionals. For example, assuming a function that computes a value and also collects some side effects, how does one turn the pure variant into a nomadic variant? This is trivial with a mutable collection, but a laborious exercise in monad world.
Those unfamiliar with Haskell might have a hard time visualizing.