2 ms·
Tuples are defiantly a shortcomming in Haskell's type system, although not for the reason you describe. The type of a tuple, is defined by the number of entries
by gizmo686 11y ago
Tuples are defiantly a shortcomming in Haskell's type system, although not for the reason you describe. The type of a tuple, is defined by the number of entries, and the types of those entries, so it can guarantee that it is getting passed a tuple that is (string, string, integer). If you want to guarantee that you are getting passed a tuple that is (first, last, age), then you would want to define new types that are dedicated to first names, last names, and age respectively. However, this is no different than what you would have to do to make this guarantee if you passed them in as curried arguments instead of a tuple.
The main type system weakness of tuples, is that their is no way to write a generic tuple function. For example, if you want to write a function to return the first element of a tuple, you need to encode into the type of that function the number of elements in the tuple.
In your dictionary example, use the "data" keyword to define a new type. Unless age is the same type as first and last, you cannot (easily) even create the dictionary you describe.