> For the complete documentation index, see [llms.txt](https://orasund.gitbook.io/elm-cookbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://orasund.gitbook.io/elm-cookbook/frequently-asked-questions-1/how-can-different-types-share-data.md).

# How can different types share data?

{% tabs %}
{% tab title="Question" %}

```
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
```

{% endtab %}

{% tab title="Solution" %}

```
type alias Animal =
    { name : String, data : AnimalData}

type AnimalData
    = Dog DogData
    | Bird BirdData
    
type alias DogData =
    { runningSpeed : Float
    }
    
type alias BirdData =
    { wingSpan : Float
    }

getName : Animal -> String
getName {name} =
    name
```

{% endtab %}

{% tab title="Alternative Solution" %}

```
type Animal =
    Dog DogData
    | Bird BirdData

type alias AnimalData species =
    {species| name : String}
    
type alias DogData =
    AnimalData {runningSpeed:Float}

type alias BirdData =
    AnimalData {wingSpan:Float}

getName : AnimalData species -> String
getName {name} =
    name
```

{% endtab %}
{% endtabs %}

## 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](https://www.reddit.com/r/elm/comments/aq69vq/passing_accessors_to_functions/)
