lambda icon indicating copy to clipboard operation
lambda copied to clipboard

Implement tuples

Open 71104 opened this issue 8 years ago • 3 comments

The main difference between tuples and lists is that the former have heterogeneous types, while the latter have only one inner type.

For example, we can have a list of integers and a tuple of (real, boolean), but not the opposite.

A consequence of this is that tuples have a finite arity/length that is known at compile time, while lists can grow arbitrarily. This is because infinite different types can't possibly be expressed.

71104 avatar Aug 17 '16 13:08 71104

This is actually mandatory because lists are not well suited to specify the arguments for native functions because they have uniform inner type. When the type system is activated, it will no longer be possible to specify heterogeneous arguments to native functions. Therefore, tuples must be used.

Marking this as a bug.

71104 avatar Oct 22 '16 14:10 71104

Tuple types must always be included in round brackets, otherwise the commas would create an ambiguous syntax:

fn x: string, string -> ...

The above is actually not ambiguous in current versions of Lambda because string is a keyword and can't be used as a parameter name, but the parser for that wouldn't be easy to implement. It is way better to disambiguate like this:

fn x: (string, string) -> ...

71104 avatar Oct 25 '16 02:10 71104

TODO list:

  • deconstructions,
  • operators,
  • string formatting.

Operators can only be applied on tuples of the same arity. Applying an operator to a pair of tuples is equivalent to applying it to each pair of elements.

71104 avatar Oct 26 '16 21:10 71104