Open lue-bird opened 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
List { url : String }
Model
Adding | before the first variant makes the variants more obvious and explicit:
|
type WrongModel = | List { url : String } type alias CorrectModel = List { url : String }
type Model = List { url : String }
would produce a nice error message, as the compiler knows that you want an alias there.
=
type
Dropping type and type alias would make it even cleaner:
type alias
Point = { x : Float, y : Float } Fruit = | Pear | Banana { angle : Float }
Thanks for reporting this! To set expectations:
Finally, please be patient with the core team. They are trying their best with limited resources.
Single constructor union types feel error-prone for beginners. One example:
Adding
|
before the first variant makes the variants more obvious and explicit:would produce a nice error message, as the compiler knows that you want an alias there.
=
placement becomes consistent with all no-type
constructsDropping
type
andtype alias
would make it even cleaner: