5 ms·
You mean that the tuples' size is statically known at the calling site, while your message could be interpreted as the size being statically known in the callee
by dazzlefruit 3y ago
You mean that the tuples' size is statically known at the calling site, while your message could be interpreted as the size being statically known in the callee.
I think this is clearer. The statement "arbitrary fixed-size tuples" sounded a bit like "an immutable mutable variable". It doesn't really say what's arbitrary about the tuples and in what context the size is fixed.
- Timon3 3y agoConsidering the opposite is called a "variable-length tuple", and I wanted to express that I'm talking about arbitrary tuples with non-variable length, what wording would have made this clearer?
- dazzlefruit 3y agoWhat's missing is in which context the tuple's length is variable, and in which context it is fixed. You can have a tuple size fixed everywhere (because the callee sets it) or a tuple size fixed at each call (and propagated to the callee statically). "Arbitrary" doesn't really help because it could refer to the elements' values, to their types, or to the tuple's length. Also "arbitrary" and "variable-length" sound like synonyms to me. Guido might use some expressions in the context of Python steering discussions but that doesn't make them less obscure for the rest of us who read C++ docs every day instead.
- Timon3 3y ago> What's missing is in which context the tuple's length is variable, and in which context it is fixed. Simple example: a function has a parameter whose type is "variable-length tuple of int". You can pass any tuple in that is known to have 0..n elements, all of type int. What would you have me call that, other than the name I've seen used in discussions on this feature? > "Arbitrary" doesn't really help because it could refer to the elements' values, to their types, or to the tuple's length. Read it as (arbitary (fixed-size tuples)). It was meant to forgo answers describing functions with known tuple sizes.
- dazzlefruit 3y ago> Simple example: a function has a parameter whose type is "variable-length tuple of int". You can pass any tuple in that is known to have 0..n elements, all of type int. And n is fixed at the calling site, right? I wonder if something like "TypeVar, but for a list of type arguments" could solve your problem. What's funny is that this is already kind of implemented in `typing.Concatenate`, but only for function parameters [1], not for type hint parameters. Anyway, I would have written "a well-typed function that concatenates two arbitrary tuples whose size is statically known at the call site". Can't really remove "at the call site" or "statically known" without being ambiguous. Edit: just found out about `TypeVarTuple`. So really we're only missing `concatenate`. [1] https://docs.python.org/3/library/typing.html#typing.Concatenate https://docs.python.org/3/library/typing.html#typing.Concate...
- Timon3 3y ago> And n is fixed at the calling site, right? I wonder if something like "TypeVar, but for a list of type arguments" could solve your problem. Yep, and TypeVarTuple should - all the syntax etc. is in place, there is an Unpack operator for TypeVarTuples, allowing you to e.g. append or prepend individual types to a TypeVarTuple. But you can't unpack more than one TypeVarTuple in an expression, it's specifically disallowed - so I can't properly type my function.
- youerbt 3y agoI'd call that function: polymorphic over tuple length.
- Timon3 3y agoThat kind of works. I guess I keep thinking about it from the perspective of the type itself instead of the function that uses it.
- youerbt 3y agoIt can also get confusing, because in some languages there is no general notion of being a tuple or n-tuple if you wish. Even if they are casually all called tuples. For example in Haskell 2-tuple and 3-tuple are simply distinct types, as distinct as Int is from String. You can't speak to the type system about "all n-tuples".