Use type alias when you want an abbreviation for a long type name. If you don't want to write List (Dict String SomeVal) over and over again, you can make a type alias to shorten it.
Use a type alias to give a name to record types, and this also gives you a nice shorthand constructor. If you do type alias P2D = {x : Float, y : Float} then you can do P2D 0.0 1.0 as equivalent to {x = 0.0, y = 1.0} and it saves you the effort of writing the literal record type over and over again. Use a type when you want to create a new type, that's distinct in the compiler. So if you want to distinguish FileName from String, you can make a type, and this will ensure that you have to tag any strings with FileName to use them where a FileName is expected. And, if you want to define constructors and variants for your type (i.e. a tagged union), or do anything with recursive types, use type, since type alias doesn't allow this. Why not use *type* everywhere? > Because then you would have to pattern match every time you used an alias for something, and if you don't want the two types to be distinct in the compiler, then that's a lot of overhead with no benefit. On Sun, Dec 18, 2016 at 3:57 PM, Richard Haven < richardha...@santacruzsoftware.com> wrote: > When should one use *type *and when should one use *type alias*? Why not > use *type* everywhere? > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elm-discuss+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.