5 ms·
At the risk of being a little pedantic, >> isn't combining two functions, e.g. Just () >> Nothing == Nothing Nothing >> Just () == Noth
by tel 12y ago
At the risk of being a little pedantic, >> isn't combining two functions, e.g.
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.
- fractalsea 12y agoBy "combining" I just meant an operator that takes multiple functions and returns a new function based on those arguments. I guess these "functions" are a special case because they are constant monadic functions. Do you mean to say composition rather than combination when you are about >=>?
- tel 12y agoYeah, I'm happy to abide by this all when the caveats are specialized, but >=> is definitely and directly what's being appealed to. 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 :)
- innguest 12y agoYes, but let's be careful not to confuse beginners that thought they were on the path to understanding and then you come and say "it's not combining two functions". 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.
- tel 12y ago>> certainly never combines two functions! The closest you can come is to specialize the monad in context to ((->) e) and then talk about that kind of combination. The other way to go is to see >> as a special case of >=> wherein constant Kleisli functions are applied. I've got no problem with that now... Except now you're really talking about >=> and you may as well be specific?
- innguest 12y agoYou missed my point. Haskell beginners do not know we use the word "morphism" for the most generic "take an input, give an output" thing (the most generic map). That's why they call it "function". It's not wrong, just not specific enough. Does (>>) not combine two maps?
- tel 12y agoIt... doesn't. 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) ()
- innguest 12y ago> It... doesn't. It does! :) > How do you interpret (>>) :: Monad m => m a -> m b -> m b as combining two maps of any kind The answer is in your question. Is -> not an arrow? Isn't there one of those arrows pointing into and out of every m x in the signature above? (for the first and last m x, there could be arrows pointing in and out, respectively). That means they are maps. A morphism is any value that has arrows pointing to it (from other values) and out of it (to other values). Read my answer above as well. I am not debating your arguments. I know you know what you are talking about and you are right in what you're saying otherwise. What I am saying is in Haskell everything except Bottom is a categorical morphism, and you seem to be ignoring this concept, which is helpful for those who are trying to make sense of all this.