Closed asujeeth closed 9 years ago
Can this be solved by adding the following implicit conversion?
implicit def any2RepUnit[A](a: Rep[A]): Rep[Unit] = unit(())
Anyway, IMHO, the fact that the Scala compiler allows to return any value for Unit
is a bug. Programmers should always explicitly write ()
if their expression has not type Unit
I would not use the suggested implicit. Rep[Unit] <: Rep[AnyVal] which means that you can assign anything to Rep[AnyVal] and that is a soundness issue.
What is the meaning of Rep[Unit]? Maybe it should not exist in the first place and we should just use Unit. Then the regular Scala conversion would work well.
I would not use the suggested implicit. Rep[Unit] <: Rep[AnyVal] which means that you can assign anything to Rep[AnyVal] and that is a soundness issue.
I agree.
What is the meaning of Rep[Unit]?
A delayed computation of type Unit
. I don’t think we can use Unit
instead of Rep[Unit]
: how would you then differentiate delayed computations from “usual” computations?
Yes it is delayed, but there is nothing you can do on it except for AnyVal operations which are anyhow infix. http://www.scala-lang.org/api/current/index.html#scala.Unit
The idea here is to give up staging of unit for the nicer interface.
Doesn't seem like much can be done about this at the framework level.
Blocks that return Rep[Unit], e.g. foreach, sometimes fail if the last statement is not actually Unit. The error message is often confusing, and requires users to manually insert a final "()".