acton
acton copied to clipboard
Replace list attribute index with a builtin function
Proposal
The builtin type list[A] has the attribute def index[B(Eq)](self, val: B, start: int=0, stop: ?int) -> int: """Return the index of the first occurrence of val in the list
The optional arguments start and stop are interpreted as in slice
notation and will limit the search to the slice of the list from start
to stop.
Raises KeyError if val is not in the searched list / slice.
"""
NotImplemented
It is mentioned in builtin.act that this should "be improved", but I think it is more than an improvement; it is a bug fix. The parameter val should have type A, but this function requires that A implements Eq, which is not necessary for lists in general. The type system does not allow this so val is given another type B. This must be changed.
We should instead have a function index[A(Eq)] (lst: list[A], val: A, start: int=0, stop: ?int) -> int
I volunteer to implement this (and int will soon be replaced by i64).
Motivation
See above
Alternatives
None.