|
|
|
|
|
by kmill
3358 days ago
|
|
Function composition is a monoid, but it is not a monad, even though the words sound similar. So it's not really getting them to the same place, but I'm not going to offer any opinion on whether someone needs to study category theory. Not quite function composition, but given a type a, (a ->) is a monad (the so called "reader monad"). We have return :: x -> (a -> x)
return x = \a -> x
(>>=) :: (a -> x) -> (x -> (a -> y)) -> (a -> y)
m >>= f = \a -> f (m a) a
(Incidentally, these are two of the Łukasiewicz axioms for propositional calculus.)It is a functor with fmap :: (x -> y) -> (a -> x) -> (a -> y)
fmap f m = \a -> f (m a)
In the case x=y, then fmap takes the monoid of functions on x to the monoid of functions on (a -> x).Venturing into more abstract territory, "a monad is a monoid in the category of endofunctors of a category C." (This has never helped me with understanding how to use monads in Haskell.) Basically, the choice of endofunctor is the type constructor for the monad, the unit map is `return` and the composition map is `join`. |
|
> return x = \a -> x
>
> (>>=) :: (a -> x) -> (x -> (a -> y)) -> (a -> y)
> m >>= f = \a -> f (m a) a
>(Incidentally, these are two of the Łukasiewicz axioms for propositional calculus.)
Also the K and S in SKI combinator calculus https://en.wikipedia.org/wiki/SKI_combinator_calculus