Basic streaming, request for comments
It would be really nice to have a couple of examples showcasing the various features so that I can get an idea of how to use it :)
By the way, here's Unison's Stream effect and Each effect (lazy nondeterminism from a stream)
Each.toList do
use Nat <
a = Each.range 0 5
b = each [1, 2, 3]
guard (a < b)
(a, b)
Can we maybe translate some Unison examples to Effekt to compare? That would be nice. @phischu could you please look into the Unison implementation as well?
If you comment out the broken functions you can actually write an example which might look like this:
val (_, l) = gatherList[Int, Unit] {
for[Int, Unit] { range(0, 5) } { i =>
for[Int, Unit] { range(1, 3) } { j =>
do emit(i + j)
}
}
}
println(l)
Please note the explicit type arguments which are necessary because I need to say WHICH stream I want to handle.
This prints:
Cons(1, Cons(2, Cons(2, Cons(3, Cons(3, Cons(4, Cons(4, Cons(5, Cons(5, Cons(6, Nil()))))))))))
As you might guess, I really do not like having to annotate the types... I also don't like binding and ignoring unit in this example. It is very easy to get this example to something like:
val l = List[Int].collect {
with i = Stream[Int].for { range(0, 5) }
with j = Stream[Int].for { range(1, 3) }
do emit(i + j)
}
println(l)
using a bit of phantom magic.
Please note the explicit type arguments which are necessary because I need to say WHICH stream I want to handle.
How about
on[Int].for { ...
Or we try to fix this at the language level.
(lazy nondeterminism from a stream)
This is planned in Phase 3
could you please look into the Unison implementation as well?
I am looking at the streaming library, which is great.
on the language level probably means fixing type inference which is planned but will take a while
@phischu I took the liberty to add some doc comments.
Interesting, the tests pass on my machine but apparently they now leak memory...
To avoid having to rebase over and over again, I am in favor of just merging this and revising later. It is in a state that is already useful and we can continue improving it.
@phischu I'll give you the approve and if you deem it ready, just merge.
Before merging, please rename the PR (just so that the autogenerated Changelog for the next release is a little more understandable 😇)