Define head
, tail
, last
with patterns, or expose the list selector with type index?
#1680
Labels
design needed
We need to specify precisely what we want
Currently they are defined with indexing, but it might be nicer to just use pattern matching, for example like this:
This (subjectively) is more elegant, and also avoid the need to specify explicit indexing type. However, we should be a little careful to not affect performance. In particular, it'd be nice to do a few optimizing rewrites. To see why, consider how these patterns are desugared:
The first optimization that would be nice to do is to replace
splitAt
withdrop
if the first components is not used:The next optimization would to notice that
bs
is only used in one place, and that place is a slector, and selecting from adrop
is the same as just selecting a bigger number (list_select
{a} (drop{b} xs) = list_select
{a+b} xs` to get:While none of this is particularly complicated, it would require a bit of work. Another option would be to just expose the list selector where the index is a type, which is useful for indexing with constants.
The text was updated successfully, but these errors were encountered: