I have a function
add2Maybe :: (Num a) => Maybe a -> Maybe a -> Maybe a
add2Maybe x y = do
n1 <- x
n2 <- y
return $ n1 + n2
It will successfully return Just 8
when called with Just 3
and Just 5
. What I want is when this fuction is called, similar to printf debugging in C, printing
The number in x is 3. --(Or Nothing).
The number in y is 5.
Final result is 8.
and return Just 8
.
I concluded that to define a function like this, I have to use Maybe monad with IO monad, but the type signiture of >>=
doesn't allow to use more than two monad in a single function. Is there a way to combine Maybe monad and IO monad, and more generally, is there a way to combine two or more monad types?