# Purpose of 3-tuples

**URL:** <https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764>\
**Category:** Learn\
**Created:** [May 12, 2020, 3:08am UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764 "2020-05-12T03:08:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DullBananas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dullbananas/32/3709_2.png) [@DullBananas](https://discourse.elm-lang.org/u/DullBananas)\
**Post date:** [May 12, 2020, 3:08am UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/1 "2020-05-12T03:08:23Z")

</div>

What are tuples with 3 elements ever useful for? I have only ever used ones with 2 items.

---

<div class="post-metadata">

**Author:** ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)\
**Post date:** [May 12, 2020, 8:27am UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/2 "2020-05-12T08:27:23Z")

</div>

`update` usually evaluates to `(Model, Cmd Msg)` but if you want to send information upward for some reason, you can change that `(Model, Cmd Msg, OutMsg)`.

Another, very similar case is when you are editing a context. There is the context, some state and possible effects. You will get into a similar `(Model, Cmd Msg, Context)` where instead of being a message, the third value is the potentially updated context.

There are also some exceptional contexts where you need to pattern match agains 3 values when implementing some logic.

---

<div class="post-metadata">

**Author:** ![sashaafm](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/sashaafm/32/453_2.png) [@sashaafm](https://discourse.elm-lang.org/u/sashaafm)\
**Post date:** [May 12, 2020, 8:33am UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/3 "2020-05-12T08:33:51Z")

</div>

I think one of the most common use cases is coordinates

```auto
type alias X = Int
type alias Y = Int
type alias Z = Int
type alias Coords = (X, Y, Z)

```

however, this opens the door to why tuples were limited to 3-tuples when there are use cases for more than that. I believe there was a blog post somewhere detailing the reasoning, but I still remember Elm 0.18 allowed for larger tuples

---

<div class="post-metadata">

**Author:** ![pdamoc](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/pdamoc/32/36_2.png) [@pdamoc](https://discourse.elm-lang.org/u/pdamoc)\
**Post date:** [May 12, 2020, 8:49am UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/4 "2020-05-12T08:49:37Z")

</div>

This is hinted towards when you attempt to create larger tuples.

> <https://github.com/elm/compiler/blob/master/hints/tuples.md>

For my taste, I think limiting the number of parameters in a function to 3 would also improve a lot of code. I try to aim for a maximum of 2 arguments with 3 being exceptional cases.

---

<div class="post-metadata">

**Author:** ![wolfadex](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/wolfadex/32/2461_2.png) [@wolfadex](https://discourse.elm-lang.org/u/wolfadex)\
**Post date:** [May 12, 2020, 12:55pm UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/5 "2020-05-12T12:55:36Z")

</div>

For what it’s worth, Deno is recommending a similar approach of 2 arguments for most functions [https://github.com/denoland/deno/blob/master/docs/contributing/style\_guide.md#exported-functions-max-2-args-put-the-rest-into-an-options-object](https://github.com/denoland/deno/blob/master/docs/contributing/style_guide.md#exported-functions-max-2-args-put-the-rest-into-an-options-object)

---

<div class="post-metadata">

**Author:** ![antew](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/antew/32/2102_2.png) [@antew](https://discourse.elm-lang.org/u/antew)\
**Post date:** [May 12, 2020, 3:02pm UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/6 "2020-05-12T15:02:33Z")

</div>

I think a good rule for function arguments and tuples is: avoid ambiguity.

If you have a function that is `Bool -> Bool -> Html msg` you’ll have to go to the function definition to see what those variables actually are.

If it were instead `{ open: Bool, showBanner: Bool } -> Html msg` it is a lot clearer what it is happening when reading it.

I generally agree on fewer arguments for functions, with one exception, for `Html.lazy` you often need to pass in multiple arguments to a function to maintain laziness. Creating a record on the fly would create a new reference and break laziness. Start with the easier to read code first and then optimize it if needed though.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 22, 2020, 3:02pm UTC](https://discourse.elm-lang.org/t/purpose-of-3-tuples/5764/7 "2020-05-22T15:02:39Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
