|
|
|
|
|
by tominated
3037 days ago
|
|
The do block syntax is actually just a syntax sugar for the `bind` function (also written `>>=`). The above would de-sugar to something like this (I may have syntax wrong): getData >>= \a ->
getMoreData a >>= \b ->
getMoreData2 b >>= \c ->
getEvenMoreData a c >>= \d ->
print d
The type signature of the `bind`/`>>=` function requires that both sides be the same type of monad, so it won't actually typecheck unless all of the get data functions return the same type of monad (future, list, optional, etc).There's a number of ways to get around this in haskell (monad transformers, free/freer monads, etc) but they're all pretty complicated unless you're pretty familiar with the language. (Disclaimer I'm probably a little wrong in my description - I'm still learning haskell) |
|