71104 / lambda

The Lambda Programming Language
MIT License
19 stars 2 forks source link

Implement tuples #103

Open 71104 opened 8 years ago

71104 commented 8 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

TODO list:

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.