|
|
|
## Array Indexing
|
|
|
|
|
|
|
|
|
|
|
|
Array indexing currently uses the `!` infix operator. However, `!` is also used by the [BangPatterns](bang-patterns) proposal, which leads to some interesting parsing issues if you try to combine the two (parterns are usually parsed as expressions in Haskell due to ambiguities).
|
|
|
|
|
|
|
|
|
|
|
|
Furthermore, it seems more consistent to reserve `!` to mean "strict", which it does in other contexts: constructor field declarations, the `$!` operator, and [BangPatterns](bang-patterns). Later we might want to introduce `!` as a general type operator.
|
|
|
|
|
|
|
|
|
|
|
|
If we remove `!` as array indexing, what do we use instead? If the [CompositionAsDot](composition-as-dot) proposal is adopted, then that leaves `.` free to be used for "selection", and array indexing is definitely a form of selection, so perhaps one of the following syntaxes would be appropriate:
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
array.(i)
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
This is unambiguous if `e.x` is to be used for record field selection. An arbitrary expression would of course be allowed inside the parentheses.
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
array.[i]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Also unambiguous, but inconsistent with the use of `[]` for lists.
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
array.#i
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
This doesn't even require any new syntax, because `.#` is a valid infix operator. |