This is several questions rolled into one:
In
donotation, does each line have to return the same type? For example, can I write one line in a singledoblock that returns anIOmonad, and another that returns an integer? (My understanding, based on how the de-sugaring with>>and>>=seems to work, is that the answer is no.)If not, then how does the compiler determine what type the lines must all return? In all the examples I've seen, the author takes it as a foregone conclusion that we're just working with
IOmonads. But how do you know, for a givendoblock, what each line must return?Again assuming the answer to #1 is no: How do you use functions that don't return the right kind of monad inside a
doblock? For example, consider this websockets code:application :: MVar ServerState -> WS.Request -> WS.WebSockets WS.Hybi00 () application state rq = do WS.acceptRequest rq msg <- WS.receiveData :: WS.WebSockets WS.Hybi00 Text return ()Suppose I want to print the value of
msg. How would I go about that in a way that doesn't conflict with the type of thedoblock?
(>>=)and(>>)) the mechanism at hand is exactly the same as for any other type class and not specific to do-notation andMonads. - chris