【发布时间】:2017-02-28 23:19:22
【问题描述】:
考虑以下示例代码:
-- Update the fields of a record. (It must have the fields already.)
{ person |
name = "George" }
-- Update multiple fields at once, using the current values.
{ particle |
position = particle.position + particle.velocity,
velocity = particle.velocity + particle.acceleration }
在这个例子中应该如何阅读|,通常在 Elm 中?
我熟悉它在集合构建符号中的“where”/“such that”,在 Haskell 的列表推导中,它具有非常相似的目的,例如
[ x*2 | x <- [1..10] ]
逻辑上等价于
(显然我也熟悉它在类 C 语言中用作一元“或”运算符)
type Msg = Increment | Decrement 之类的呢?
或者,在这个例子中讨论Union Types时:
type Boolean
= T
| F
| Not Boolean
| And Boolean Boolean
| Or Boolean Boolean
【问题讨论】:
-
我不知道它有多官方,但我总是说“在哪里”。例如,姓名为 George 的人。
-
@Joe 但是guide.elm-lang.org 中的
type Msg = Increment | Decrement之类的呢? -
上下文很重要。在那种情况下,我说“或”。类型 Msg 是增量或减量。不知道为什么这没有在第一条评论上发布。
-
它只是一个分隔符,你不要读它。列举项目(例如苹果、香蕉和橙子)时,逗号也不发音。
-
@JanTojnar 谢谢。我不确定为什么文档中没有明确的解释。