concept List in category elm

appears as: List
Elm in Action

This is an excerpt from Manning's book Elm in Action.

  • It has no fields or methods. You work with it by using functions from the List module.
  • Because it is a linked list, you can ask for its first element, but not for other individual elements. (If you need to ask for elements at various positions, you can first convert from an Elm List to an Elm Array. We’ll discuss Elm arrays in chapter 3.)
  • That just ain’t so! Array.fromList can return only an array whose elements have the same type as the list it receives. Its type annotation must reflect that, by having the same type variable for both the List it accepts and the Array it returns.

    Finally, you learned about Maybe, the container value that Array.get returns to represent the potential absence of a value. Table 3.8 compares Maybe and List.

    Table 3.8. Comparing Maybe and List (view table figure)

    Container contents

    List

    Maybe

    Empty [] : List a Nothing : Maybe a
    One value [ "foo" ] : List String Just "foo" : Maybe String
    Two values [ "foo", "bar" ]: List String Not possible!