How can different types share data?

type Animal
    = Dog DogData
    | Bird BirdData
type alias DogData =
    { name : String
    , runningSpeed : Float
type alias BirdData =
    { name : String
    , wingSpan : Float

{-| This function should work for all Animals
getName {name} =


How can I write one function for all animals, that returns just the name.


Put the common data, in our case the name, all in one case and separate it from the differing data.

Further Reading

Last updated