O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use Extensible Records

Now that you’ve organized the salad state, you need to handle the contact-related state. You’ve seen the pitfalls of nested state. In this section, you will learn a different approach by using extensible records to create a Contact type without nesting state. Yet, you will still build a separate updateContact function that only changes contact-related fields.

Extract the Contact

You need to make a Contact type alias, but it will differ from the type aliases you’ve made previously. Below the Salad type alias, add this code:

 type​ ​alias​ ​Contact​ c =
  { c
  | name : ​String
  , email : ​String
  , phone : ​String
  }

This is an extensible record type. An extensible record resembles ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required