Logo

Programming-Idioms

  • Ruby
  • C++
  • Haskell

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.

#include <tuple>
auto t = std::make_tuple(2.5f, std::string("foo"), false);

Types are inferred.
#include <tuple>
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.
t = [2.5, "hello", -1]
t = (a, b, c)
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