Hi all,
I am wondering if implicit conversions have been considered as a feature. They are one of the core features of Scala and, if used correctly, they can be very powerful. For example, I was recently looking into literal conversion to types and I noticed that it's quite hard to add support for say literal to Tensor<Int32>
conversion; a main issue being the resulting ambiguity when calling overloaded functions. So, I was thinking that syntax like the following could be used to support implicit conversions in Swift:
@implicitConversion(precedence: ...)
func scalarToTensor<Scalar: TensorFlowScalar>(_ value: Scalar) -> Tensor<Scalar> {
...
}
This would also allow for setting a precedence level for conversions to avoid ambiguous resolution errors (which were quite common in Scala 2). It would also go a long way in supporting custom DSLs (for which there seems to be a strong push currently in the Swift community with the function builders proposal).
So, are implicit conversions a feature that has been considered or, if not, that could be considered if a pitch was made for it? Also, given that we decided to go with something like this, how difficult would it be to support it in the compiler?
Thanks,
Anthony