compiler icon indicating copy to clipboard operation
compiler copied to clipboard

Different type syntax

Open lue-bird opened this issue 3 years ago • 1 comments

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 }
  • type Model = List { url : String }
    
    would produce a nice error message, as the compiler knows that you want an alias there.
  • = placement becomes consistent with all no-type constructs

Dropping type and type alias would make it even cleaner:

Point =
    { x : Float, y : Float }

Fruit =
   | Pear
   | Banana { angle : Float }

lue-bird avatar Dec 23 '21 17:12 lue-bird

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Dec 23 '21 17:12 github-actions[bot]