Mathematically, the binary operation for function application is an endo-Functor/Monad.
pipe :: (a -> b) -> a -> b
pipe = \f -> \a -> f a
(|>) :: a -> (a -> b) -> b
(|>) = flip pipe
infixl 1 |>
It's called pipeline-operator, and in Haskell, predefined as
https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Function.html#v:-38-
(&) :: a -> (a -> b) -> b
monadTestPipe :: IO ()
monadTestPipe = do
"Monad Laws========" & print
let i = id
let a = (3 :: Int)
let f = (\a -> a + 1) >>> i
let g = (\a -> a * 2) >>> i
let m = f a -- 4
"---------------------------------" & print
do
"-- Left/Center/Right identity" & print
let lft = a & i & f
let ctr = a & f -- = m
let rit = a & f & i
---------------------------------
lft & print -- 4
ctr & print -- 4
rit & print -- 4
"---------------------------------" & print
do
"-- Associativity" & print
-- m = f a -- 4
(m & f) & g
& print -- 10 = (4+1)x2
m & (\x -> f x & g)
& print -- 10
"---------------------------------" & print
Why is the pipeline-operation (&) :: a -> (a -> b) -> b
not treated (at least not integrated) as Monad in Haskell?
Or, it's probably fine to say, I've never read that in any Haskell wiki or books.
Edit: I want to make my question as concise as possible in order to prevent diffusion of issues, but
class Applicative m => Monad m where
(>>=) :: m a -> (a -> m b) -> m b
return :: a -> m a
>>=
is simply a symbol of Monad type class in Haskell, and &
can be integrated to >>=
because &
is a monad operator in mathematical sense.
return
is id :: a -> a