I’m writing the following code, where the interesting bit is in the capture set of oneOf.
//> using scala 3.nightly
//> using option -language:experimental.captureChecking -nowarn
import caps.*
trait Rand extends SharedCapability:
def range(min: Int, max: Int): Int
def nextInt(max: Int): Rand ?-> Int =
r ?=> r.range(0, max)
def oneOf[A](head: Rand ?=> A, tail: (Rand ?=> A)*): Rand ?->{head} A =
val all: Seq[Rand ?->{head, tail*} A] = head +: tail
all(nextInt(all.length))
Instinctively, I would expect oneOf to return Rand ?→{head, tail*} A, and am a little weirded out that the above code compiles. Isn’t this forgetting the fact that whatever is contained by tail is tracked?
I do need all to explicitly capture {head, tail*}, so my expectations seem at list a little reasonable…