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} =
name
Question
How can I write one function for all animals, that returns just the name
.
Answer
Put the common data, in our case the name, all in one case and separate it from the differing data.
Further Reading
👥Thread: Passing accessors to functions
Last updated
Was this helpful?