Zulip Chat Archive
Stream: lean4
Topic: Feature Request: Index with ranges
Henrik Böving (Aug 13 2022 at 18:35):
Is there a reason that given r : Std.Range
and xs : Array Expr
or List Expr
we do not support xs[r]
because there is no GetElem
instance for this configuration? It could even be constructed automatically from instances of GetElem
for the beginning and end of r
.
Mario Carneiro (Aug 13 2022 at 18:38):
the syntax for that would be a bit off, xs[[1:5]]
Mario Carneiro (Aug 13 2022 at 18:38):
also, what would it return?
Mario Carneiro (Aug 13 2022 at 18:39):
I think the syntax arr[i:j]
currently returns a Subarray
Henrik Böving (Aug 13 2022 at 18:45):
Sounds to me like it would be reasonable to return a subarray as well then?
Henrik Böving (Aug 13 2022 at 20:28):
Oh and to make clear why I'm asking, when there is an Std.Range stored in some datastructure you actually have this case of r : Std.Range
instead of the arr[i:j]
syntax so I'm mostly asking for this case, I see the argument against it though.
Sebastian Ullrich (Aug 13 2022 at 20:49):
Ah, I wanted to create an RFC about this at some point, but here is the gist: as Mario said, the current range syntax would look a bit weird inside indexing syntax, but also it's a bit weird for range syntax in itself. If we switched to a more common notation like i..j
(or i..<j
for explicitness, and then i..=j
for inclusive ranges), using ranges as indices would become very natural.
Last updated: Dec 20 2023 at 11:08 UTC