elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Different type syntax #2238

Open lue-bird opened 2 years ago

lue-bird commented 2 years ago

Single constructor union types feel error-prone for beginners. One example:

type Model = List { url : String }

initialModel : Model
initialModel =
    [ { url = "1.jpeg" } ]

type List { url : String } doesn't match Model

Adding | before the first variant makes the variants more obvious and explicit:

type WrongModel =
    | List { url : String }

type alias CorrectModel =
    List { url : String }

Dropping type and type alias would make it even cleaner:

Point =
    { x : Float, y : Float }

Fruit =
   | Pear
   | Banana { angle : Float }
github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.