by slver · 5y ago · 0 comments
Ultimately all objects/structs/records are at their core tuples. But we refer to their attributes by name for a good reason.
match (a, b) with:
(4, 2) => "Hello"
(1, 0) => "World"
(_, _) => "nope" match (n % 3, n % 5) with:
(0, 0) => print "FizzBuzz"
(1, 0) => print "Fizz"
(0, 1) => print "Buzz"
(_, _) => print nI never heard about a real-world problem associated with fizz-buzz, besides teaching children to count. Do you have some documentation about that?
JS has made a few steps in allowing us to have objects as compact as a tuple, i.e. {foo, bar, baz}.
I think we need more effort in that direction. But keep fields addressable by name at all times. In fact, ordered arguments in functions have the same problem (they're a tuple). Unfortunately that ship has sailed.
Besides, you may end up with divergences in your community about how local a tuple should be allowed to be. Can it be passed to a lambda? Can you map over it in a local context? etc. Overall, deciding where tuples should be used is an easy choice for the developer, and a very hard choice for the language creator.
I agree that this would be an amazing thing to have, but I've never seen those anywhere in practice (not even in Idris). My gut-feeling tells me that it might not work in combination with composability in the sense that there might never be a proper global "equal" that everyone can agree one.
I'm curious - besides the ones mentioned, are there any other fundamental type concepts that you would build into your own programming language? :)