3 ms·
Isn't the identity monad isomorphic to normal functions? In that sense normal functions are a monad.
by Tarean 10y ago
Isn't the identity monad isomorphic to normal functions? In that sense normal functions are a monad.
- kmill 10y agoI checked that while I was writing my comment, and I don't believe there is such an isomorphism. For the identity monad, we have the following functions: return :: a -> a return = id join :: a -> a join = id If this were isomorphic to the function composition monoid, there would be some way to interpret join as function composition, but I don't see it. Please show me if you know the isomorphism! (My thinking is a bit fuzzy on this, but it appears to me that the identity monad is actually isomorphic to a trivial monoid --- if you want, you can model the trivial monoid as the one-element set {0} under addition.) Bind is (>>=) :: a -> (a -> b) -> b (>>=) = flip id that is, function application. Still no function composer in sight, though.
- BoiledCabbage 10y agoAt this point I admit I'm way beyond my depth. This article seems to imply a correlation between the fish operator (<=<) and composition. Specifically his section on Kleisli monad. http://www.haskellforall.com/2012/08/the-category-design-pattern.html?m=1 http://www.haskellforall.com/2012/08/the-category-design-pat... But I don't know the space well enough to know if that's answering your question.
- kmill 10y agoIt's true that the Kleisli category gives a composition law from a monad, but let's not lose sight: the point isn't whether there is a conceivable way to compose things, but whether a monad is just a monoid of functions under composition. Monads are like a monoid at the type level plus a bunch of coherence rules. For every type a, there is a "composition" m (m a) -> m a and a "unit" a -> m a. (Compare with a monoid, where there is a composition m x m -> m and a unit {1} -> m.) Also, the composition must be natural in the sense that whenever there is a map f :: a -> b then you have a bunch of "commuting squares": the composition m (m a) -> m (m b) -> m b must equal m (m a) -> m a -> m b and the composition a -> m a -> m b must equal a -> b -> m b. (Some of these maps are fmap f or fmap (fmap f).) The naturality thing is important and shows up quite a lot, and category theory was invented to understand naturality. It's sort of a higher higher order functional programming.
- BoiledCabbage 10y agoThanks this was helpful. And you're right. I was blurring the concept of composition and actual functional composition. Clearly much more to learn.