This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Caml
- C++
- C++
- C#
- D
- D
- Go
- Go
- Haskell
- JS
- Java
- Java
- Java
- Java
- Kotlin
- Pascal
- Perl
- Perl
- Python
- Python
- Ruby
- Rust
- VB
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.
Type inference can determine the type of the tuple without annotation.
std::tuple<float, std::string, bool> t(2.5f, "foo", false);
Strongly typed, can include any primitive or class and be of arbitrary (but fixed) length.
auto entry = tuple!("index", "value", "active")(4, "Hello", true);
Field names can be provided.
entry.index is 4, etc.
entry.index is 4, etc.
a, b, c := 2.5, "hello", make(chan int)
a, b, c are strongly typed and could hold the multiple return values of a func.
While a, b, c can most often be used like a tuple, they are technically not a tuple named t.
While a, b, c can most often be used like a tuple, they are technically not a tuple named t.
t := []any{
2.5,
"hello",
make(chan int),
}
A slice of empty interface may hold any values (not strongly typed).
record Tuple(int a, String b, boolean c) {}
var t = new Tuple(1, "hello", true);
Strongly typed.
record is available since Java 16
record is available since Java 16
use constant t => (1, 'two', 3.5);
This satisfizes the definition of a tuple in that it is fixed length and immutable; however, it probably doesn't provide the speed advantages that a tuple enjoys in other 'strongly typed' languages.