scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

`given` cannot express implicit conversion using cbn parameter

Open two-horned opened this issue 1 week ago • 3 comments

Sometimes it is crucial to convert types without evaluating the value. For example, like this:

implicit def toB[R](x: => A[R]): B[R] = B(myFun(x))

There exists no equivalent given statement, which I wish would.

If I define a given [R]: Conversion[A[R], B[R]], the apply function has to have type A[R] as parameter, disallowing type => A[R]. So currently I am forced to use the implicit def, which is at odds with modern coding style that uses given.

two-horned avatar Dec 02 '25 20:12 two-horned