Something like Scala's <Capture Checking> would be...
# language-evolution
y
Something like Scala's Capture Checking would be really interesting for resource management in Kotlin (Especially for DSLs with receivers that are meant to not escape e.g.
SelectBuilder
,
Raise
). Scala's presentation of it is quite technical, so I wonder if it could be simplified to be more developer-friendly. I'm also writing an effects library where that would come in handy to prevent effects escaping their scope.
j
Kotlin kind of has capabilities by accident already (non local return, break/continue, suspend) in inline lambdas. I think a couple of new features for Kotlin contracts would probably be sufficient to cover most use cases of Capture Checking. On another note, this also seems like an obvious solution for checked exceptions, lambdas that are inline/have EXACTLY_ONCE contract could require that that throws annotation/try catch block is present at the call site (like with CanThrow in Scala).
y
Maybe contracts might be sufficient, I'm not sure. A key fact is that Scala's system allows you to use such checked objects inside any others e.g. you can have a
Pair<CanThrow,Int>
just fine. That's something that most of the mentioned features don't have.