In Elm Type Annotations, we learned why it is essential to add type annotations. Today we talk about important features, Elm List. This post is part of the functional language series, and it is based on a remarkable book Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
When you try to solve real-world problems with programming, you try to do it for more than one person. This implies that your program needs to handle collections. Let’s explore the Elm List collection.
Let’s recap important Elm implementation feature, it must catch in compile phase possible errors in code. This is why we can not use indices to get the List element, or we can not mix data types in List. When we create a proper list, Elm sets a static type for this List (image above).
Before compilation, Elm always knows the type of every variable and function.
- list elements are chained together, so the item only knows for the next one
- list elements must be of the same type