How does it work | character read in Elm?

Consider the following code example:

-- 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 }

Source: Learn Elm in X Minutes

How to read |in this example and in Elm in general?

I am familiar with it in set-builder notation as "where" / "such that", and in the contexts of a list in Haskell it has a very similar purpose, for example.

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

logically equivalent

enter image description here

source: Teach you A Haskell

(Obviously, I am also familiar with its use as a unary "or" operator in languages ​​like C)

How about something like type Msg = Increment | Decrement?

Source: https://guide.elm-lang.org

Or in this example, when discussing Connection Types :

type Boolean
    = T
    | F
    | Not Boolean
    | And Boolean Boolean
    | Or Boolean Boolean
+4
1

"". :

type Msg = Increment | Decrement

"a Msg is Increment Decrement". , Result:

type Result error value
    = Ok value
    | Err error

: a Result Ok value, Err error ".

, , "", "where". :

{ person | name = "George" }

- person name, "George" "( " = "" ", , , , , person). , , .

+9

Source: https://habr.com/ru/post/1671085/


All Articles