元组刘海图案
我明白,在:
fx = x + 1 where !y = undefined
中,爆炸模式的含义是 y
将在 f
之前评估>。
类似地:
fx = x + 1 其中 !(!a, !b) = (undefined, undefined)
对于 x
和 y< 来说,含义是相同的/代码>。
但是 bang 模式的含义是什么:
fx = x + 1 where (!a, !b) = (undefined, undefined)
它似乎不会导致 undefined 被评估。元组内爆炸模式何时生效?如果模式的元组是强制的?谁能举一个 (!a, !b) = (..)
与 (a, b) = (..)
不同的例子?
I understand that in:
f x = x + 1 where !y = undefined
the meaning of the bang pattern is that y
is to be evaluated before f
.
Similarly:
f x = x + 1 where !(!a, !b) = (undefined, undefined)
the meaning is the same, w.r.t x
and y
.
But what do the bang patterns mean in:
f x = x + 1 where (!a, !b) = (undefined, undefined)
It doesn't seem to cause undefined to be evaluated. When do in-tuple bang patterns come into effect? If the pattern's tuple is forced? Can anyone give an example where (!a, !b) = (..)
differs from (a, b) = (..)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
元组本身的爆炸模式将强制评估元组而不是其元素。每当元组本身被评估时,元组元素上的爆炸模式都会强制它们。
以下是不同行为的示例:
A bang pattern on the tuple itself will force evaluation of the tuple but not its elements. Bang patterns on the tuple elements will force them whenever the tuple itself is evaluated.
Here's an example of the differing behavior:
如果将其翻译为
let
:在这里,您创建一个包含
(a, b)
的元组,并且当对元组求值时,同时包含a
和 b 是。但由于元组从未被求值,所以
a
和b
都不会。这与编写基本相同:由于 y 从未被评估,因此也不是未定义的。
If you translate it to
let
:Here, you create a tuple containing
(a, b)
, and when the tuple is evaluated, botha
andb
are.But because the tuple is never evaluated, neither
a
norb
are. This is basically the same as writing:Since y is never evaluated, neither is
undefined
.