I’m trying to learn Haskell but I’m having problem in monad usage.
I imported the module Data.Maybe.
But I don’t know how to use the >>= operator.
Given (>>=) :: Monad m => m a -> (a -> m b) -> m b I cannot understand how to define a function (a -> m b).
Can someone provide some pedagogical example?
For
Maybemonad bind function (>>=) looks like that:So, let’s define some
Maybe avalue:And
:: a -> Maybe bfunction:Now we can use bind like infix operator:
Another example of really
a -> Maybe bfunction could be:So
hincrement integer number, convert it to string and make aMaybevaluewith
returnfunction.