Scala allows you to put a ???
placeholder for type names that temporarily allow you to work on the rest of a type without the compiler yelling at you unless you actually try to compile it. For example:
struct ??? { //I'll think of a name later
// Right now I want to focus here...
}
There would be no error about the missing type name until I actually try to compile this (at which point it tells me I need to provide a name). Similarly, I don't always want to figure out the exact return type of a function at the moment I create the function... sometimes I want to work out the algorithm first, and then come back to the type:
func foo() -> ??? { //I'll figure out the return type later
//Right now I want to focus on the implementation
}
Again, the compiler wouldn't complain until I try to actually compile.
Finally, the thread on Opaque types has brought up the point that sometimes types are so unwieldy that it would be preferable for the compiler to infer the type instead of having to write it out. The function still has a concrete type, but that type is inferred from the return statements at compile time (and it is an error if they return different types):
func foo() -> ??? { //I am just going to let the compiler infer the type for me
return "Foo"
}
It is easy to write String as the Type here, but as pointed out in the Opaque types thread, there are types that just obscure what the function is doing like so:
LazyMapSequence<LazyFilterSequence<LazyMapSequence<Elements, ElementOfResult?>>,ElementOfResult>
In these cases, when the compiler can infer the type, instead of causing an error during compile ???
would just be replaced by the compiler with the inferred type (just like the type of x in let x = bar()
except we are explicitly asking for it). This would come at a cost of slightly increased compile times in some cases, but only where we have asked for it.
One advantage of this is that we could simplify the syntax for opaque types like so:
func foo()-> Int as Comparable //We see Int inside the function, but the outside world sees `opaque Comparable`
//We can infer the type
func foo()-> ??? as Comparable //Int is inferred from our return type, the outside world still sees `opaque Comparable`
In this case we see that inferring the return type is just the composition of the ???
placeholder feature and a definition of Opaque types which always has an explicit spot for defining the internal type. (See that thread for why I think that is important).
Anyway, I wanted to see if people would find this placeholder behavior useful on it's own (separate from Opaque Types).