简体   繁体   中英

Haskell monads: What is the name for what `(>>=)` and `(=<<)` do?

I've been playing with Haskell on and off for several years now; I'm quite comfortable with how monads work, and how to use them, and what the operators (=<<) and (>>=) do.

But I still don't know how to talk about them! Is there any standard term for what they do — for the action of transforming an arrow a -> mb into an arrow ma -> mb ?

(As a mathematician by background, one option that springs to mind is “the forgetful functor from the Kleisli category”. But Haskell gurus must surely have some more succinct term, since in Haskell, this operation is used as one of the building blocks of monads, unlike in the mathematical setting where it's usually considered as a derived operation, defined from multiplication together with functoriality!)

The official name for >>= is bind. We can also read it as "feed through", "process by", etc. Brian Benkman from MSDN's Channel 9 calls it "shove" (to the right, or to the left).

Why bind? By analogy with let . Just as let binds its variables to results of evaluating the initial expressions, the "monadic let" would "bind" its variables to results of its input computations:

let a = ....      or:      .... $>> (\ a ->      -- non-recursive "let", as in Lisp,
    b = ....               .... $>> (\ b ->      --    (Haskell's is Lisp's "letrec")
in  ....                   .... ))             where x $>> f = f x


do a <- ....      or:      .... >>= (\ a ->
   b <- ....               .... >>= (\ b ->
   ....                    .... ))

This is, as you can see, from completely non-mathematical, practical perspective.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM