Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Kotlin

Idiom #220 Create a tuple value

Create t consisting of 3 values having different types.

Explain if the elements of t are strongly typed or not.

val t = Triple(2.5, "foo", true)

Strongly typed, up to 3 elements. Pair(..) for two, use data class Foo(...) for more then 3
let t = 1, 'a', "b"

in OCaml, parenthesis for tuples are optional and only used to disambiguate.
Type inference can determine the type of the tuple without annotation.

New implementation...
programming-idioms.org