怎么样的 符号在榆树中读取?

Ben*_*n R 4 syntax elm

请考虑以下示例代码:

-- 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 }
Run Code Online (Sandbox Code Playgroud)

资料来源:X分钟学习榆树

|在这个例子中,人们应该怎么读,而在Elm中呢?

我在set-builder符号中熟悉它作为"where"/"this that",并且在Haskell中的列表理解中它具有非常相似的目的,例如

[ x*2 | x <- [1..10] ]

在逻辑上等同于

在此输入图像描述

来源:了解你一个Haskell

(显然我也熟悉它在C语言中作为一元"或"运算符的用法)

什么样的type Msg = Increment | Decrement

资料来源:https://guide.elm-lang.org

或者,在此示例中讨论联盟类型时:

type Boolean
    = T
    | F
    | Not Boolean
    | And Boolean Boolean
    | Or Boolean Boolean
Run Code Online (Sandbox Code Playgroud)

rob*_*oby 9

在类型中,我将其读作" ".在反例中:

type Msg = Increment | Decrement
Run Code Online (Sandbox Code Playgroud)

我会把它读作"a Msgis Increment or Decrement ".在一个稍微复杂但仍然常见的Result类型示例中:

type Result error value
    = Ok value
    | Err error
Run Code Online (Sandbox Code Playgroud)

我会读到"a Result或者是Oka value 或者 Errerror".

在您给出记录更新语法的示例中,我将其视为" with "而不是" where ".例如:

{ person | name = "George" }
Run Code Online (Sandbox Code Playgroud)

是" person价值它的name字段设置为"George""(而不是" 在那里的名字='乔治’"这似乎意味着,你根据什么筛选值都在person).这个是我认为比类型情况更模糊.