3

I have this

{ a |
    b = { a.b |
        c =
            Utils.newC
                a.b.c
        }
}

But the compiler just says "no" :

-- SYNTAX PROBLEM ----------------------------------------------------- Main.elm
I ran into something unexpected when parsing your code!

43|                  b = { a.b |
                            ^
I am looking for one of the following things:

     "'"
     "|"
     an equals sign '='
     more letters in this name
     whitespace

I don't know what to do now. How to get a with c property of b changed to a new value?

Algorythmis
  • 642
  • 1
  • 7
  • 19

1 Answers1

6

Updating nested records is a little more verbose in Elm than in other languages, and the syntax of { a.b | ... } updates is not allowed. Here is an alternative:

let
    b = a.b
    newB = { b | c = Utils.newC b.c }
in
    { a | b = newB }

See this related question for more information on standard ways of updating nested record values in Elm.

Community
  • 1
  • 1
Chad Gilbert
  • 36,115
  • 4
  • 89
  • 97