简体   繁体   English

Haskell monads:`(>> =)`和`(= <<)`的名称是什么?

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

I've been playing with Haskell on and off for several years now; 我已经和Haskell一起玩了好几年了; I'm quite comfortable with how monads work, and how to use them, and what the operators (=<<) and (>>=) do. 我对monad如何工作以及如何使用它们以及运算符(=<<)(>>=)作用感到很满意。

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 ? 对于它们的作用是否有任何标准术语 - 对于将箭头a -> mb转换为箭头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!) (作为背景的数学家,脑海中浮现的一个选项是“来自Kleisli类别的遗忘函子”。但是Haskell大师肯定会有一些更简洁的术语,因为在Haskell中,这个操作被用作其中一个构建块。 monads,与通常被认为是派生操作的数学设置不同,从乘法和functoriality定义!)

The official name for >>= is bind. >>=的正式名称是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). 我们还可以将其视为“直通”,“处理方式”等。 来自MSDN频道9的Brian Benkman将其称为“推”(向右或向左)。

Why bind? 为何绑定? By analogy with let . 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将变量绑定到评估初始表达式的结果一样,“monadic let”会将其变量“绑定”到其输入计算的结果:

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. 正如您所看到的,这是完全非数学的,实用的观点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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