|
|
|
## 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 (patterns are usually parsed as expressions in Haskell due to ambiguities).
|
|
|
|
|
|
|
|
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)
|
|
|
|
```
|
| ... | ... | @@ -16,6 +20,7 @@ If we remove `!` as array indexing, what do we use instead? If the [Composition |
|
|
|
|
|
|
|
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]
|
|
|
|
```
|
| ... | ... | @@ -23,6 +28,7 @@ This is unambiguous if `e.x` is to be used for record field selection. An arbit |
|
|
|
|
|
|
|
Also unambiguous, but inconsistent with the use of `[]` for lists.
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
array.#i
|
|
|
|
```
|
| ... | ... | @@ -30,21 +36,4 @@ Also unambiguous, but inconsistent with the use of `[]` for lists. |
|
|
|
|
|
|
|
This doesn't even require any new syntax, because `.#` is a valid infix operator.
|
|
|
|
|
|
|
|
## Use of '!'
|
|
|
|
|
|
|
|
|
|
|
|
A more useful definition of '!' would be
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
f ! x = x `seq` f x
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
where '!' has the exact same fixity as function application. so
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
foo !x !y
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
could be used to call foo with x and y evaluated strictly beforehand. |