If I define the “bind” function like this:
(>>=) :: M a -> (a -> M' b) -> M' b
Will this definition help me if I want the result to be of a new Monad type, or I should use same Monad but with b in the same Monad box as before?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As I’ve mentioned in the comment, I don’t think such operation can be safely defined for general monads (e.g.
M = IO,M' = Maybe).However, if the M is safely convertible to M’, then this bind can be defined as:
And conversely,
Some of such safe conversion methods are
maybeToList(Maybe → []),listToMaybe([] → Maybe),stToIO(ST RealWorld → IO), … note that there isn’t a genericconvertmethod for any monads.