File: tuples.md

package info (click to toggle)
elm-compiler 0.19.1-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,296 kB
  • sloc: haskell: 35,930; javascript: 5,404; sh: 82; xml: 27; python: 26; makefile: 13
file content (19 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# From Tuples to Records

The largest tuple possible in Elm has three entries. Once you get to four, it is best to make a record with named entries.

For example, it is _conceivable_ to represent a rectangle as four numbers like `(10,10,100,100)` but it would be more self-documenting to use a record like this:

```elm
type alias Rectangle =
  { x : Float
  , y : Float
  , width : Float
  , height : Float
  }
```

Now it is clear that the dimensions should be `Float` values. It is also clear that we are not using the convention of specifying the top-left and bottom-right corners. It could be clearer about whether the `x` and `y` is the point in the top-left or in the middle though!

Anyway, using records like this also gives you access to syntax like `rect.x`, `.x`, and `{ rect | x = 40 }`. It is not clear how to design features like that for arbitrarily sized tuples, so we did not. We already have a way, and it is more self-documenting!