by tel · 11y ago · 0 comments
Just () >> Nothing == Nothing
Nothing >> Just () == Nothing
It's perhaps viable to think of (m >> f) as modifying/continuing the m effect/computation using a continuation which is constantly the f effect. But that's about as close to "combining two functions" I can get it without specifically picking a monad that is a function.On the other hand, >=> is absolutely combining two functions. It's exactly (flip (.)) in a Kleisli category over some monad.
I meant combination just so as to generalize the idea of "composition". If you're willing to call Kleisli composition "composition" generally then I won't complain :)
Well, it is combining two morphisms - that you can't deny. And most people use the shorthand word "function" to mean "any morphism" including type constructors.
You may be technically correct but it is not incorrect for people trying to make sense of all these transformations, to say that >> combines two functions. These functions are picked up by the monadic context and executed in sequence.
I think >> also feels a lot like composing functions when we've specialized the monad to State.
It's not wrong, just not specific enough. Does (>>) not combine two maps?
We appear to be talking past one another. How do you interpret
(>>) :: Monad m => m a -> m b -> m b
as combining two maps of any kind without either (a) specializing `m` to a function type or (b) considering it syntax sugar for a >> b ===> (const a >=> const b) ()