-
Notifications
You must be signed in to change notification settings - Fork 1k
/
caps.scala
32 lines (24 loc) · 923 Bytes
/
caps.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package scala
import annotation.experimental
@experimental object caps:
/** The universal capture reference */
val `*`: Any = ()
object unsafe:
/** If argument is of type `cs T`, converts to type `box cs T`. This
* avoids the error that would be raised when boxing `*`.
*/
extension [T](x: T) def unsafeBox: T = x
/** If argument is of type `box cs T`, converts to type `cs T`. This
* avoids the error that would be raised when unboxing `*`.
*/
extension [T](x: T) def unsafeUnbox: T = x
/** If argument is of type `box cs T`, converts to type `cs T`. This
* avoids the error that would be raised when unboxing `*`.
*/
extension [T, U](f: T => U) def unsafeBoxFunArg: T => U = f
end unsafe
/** Mixing in this trait forces a trait or class to be pure, i.e.
* have no capabilities retained in its self type.
*/
trait Pure:
this: Pure =>