Having a background in powershell scripting i first thought it natural to think of function composition in a pipe kind of way. That means the syntax for composition should be fun1 | fun2 | fun3
in a psudocode kind of way. (where fun[i]
is the i
'th function to apply in order). This order of functions is also what you find in haskell monadic binds. fun1 >>= fun2 >>= fun3
.
But in other occasions in haskell, the order of functions is more math'y, such as fun3 . fun2 . fun1
, or in the functorial setting fmap fun3 . fmap fun2 . fmap fun1
.
I am very much aware that the functions have different signature in the two examples, but it puzzles me that the structure is reversed, still. My workaround is to sometimes define a function mmap = flip (>>=)
such that I can write mmap fun3 . mmap fun2 . mmap fun1
.
So to the question:
- Is there a
mmap
already defined? What is is called? - Why if bind defined as an operator with arguments in an order that feels backwards?
mmap
is, not surprisingly,=<<
. Monadic bind is not analogous to function composition; it is more like function application. – chepner