4 ms·
Besides just the convenience of it not being a dependency, this will allow other language-level features like pattern matching and object deconstruction in the
by peeters 7y ago
Besides just the convenience of it not being a dependency, this will allow other language-level features like pattern matching and object deconstruction in the future. Basically anything that requires the language to have a tuple/named tuple type.
- bobthepanda 7y ago> tuple/named tuple type As someone not familiar with using those, can you ELI5 what those are and what their benefits are?
- peeters 7y agoA tuple is the generic term for a pair, triple, etc. It's a collection of data of heterogeneous types, unlike an array which is homogeneous. When the members are unnamed, the data is indexed by its position like an array. E.g. a method could return an unnamed tuple ("foo", 7) which might have type (String, int). In some languages like ML, having tuples is such a fundamental part of the language that things like functions always act on a single argument which is actually just a tuple. So max(5, 5) is a function that takes a tuple of two ints as its parameter. When you have tuples as a first-class concept, you can start to do some interesting shortcuts like: (b, a) = (a, b); // swap two variables with no intermediate or String (first, last) = name; This is called deconstruction, where you extract a tuple into variables representing its members. This is common in a ton of languages (Typescript, C#, ML, Scala, Python, etc). It also forms a cornerstone of pattern matching expressions in some languages (Scala, Haskell) where you can create a condition and simultaneously assign the data you care about to variables that can then be used in that branch. Scala pseudocode: sum(list: ConsList<int>) { return list match { Empty(): 0; Node(first, rest): first + sum(rest); } }