effekt-lang / effekt-lang/effekt
Universal collection syntax
- Dominant language
- Scala
- Stars
- 469
- Forks
- 41
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 23
Description
While writing tests for the newly added array function in the stdlib (#839), I have found myself using the `array::fromList` function quite often. We also have briefly discussed this in one of the previous Effekt meetings and [here](https://github.com/effekt-lang/effekt/pull/743#issuecomment-2618481774); what if we had a shared syntax for creating collections?
## Idea
We re-use the `emit` effect:
```
array#[1, 2, 3]
```
is converted to
```
collectArray {
do emit(1)
do emit(2)
do emit(3)
}
```
Note that `collectArray` and other functions for collecting (ha!) collections are already implemented in [stream.effekt](https://github.com/effekt-lang/effekt/blob/d57b530c328437c62b6c4a4b1e0a0651785aab3c/libraries/common/stream.effekt#L169-L214)
such this would merely be a change in the parser similar to #743.
Of course, this would also work for `bytearray`:
```
bytes#[1.toByte, 2.toByte, 3.toByte]
```
is converted to
```
collectBytes {
do emit(1.toByte)
do emit(2.toByte)
do emit(3.toByte)
}
```
(We should probably rename `collectBytes` to just `bytes` and `collectArray` to `array` for consistency.)
## Caveats
- Possible performance & overhead penalty.
- Possibly confusing error messages similar to #743.
- The syntax does not work for maps, sets and other collections that need a comparison function. I can see this changing if and once Effekt has type classes.
## Benefits
- Nice and unique usage of effects!
- Better ergonomics
## To Discuss
- Weigh pro and cons
- Decide on syntax
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.