[Grace-core] On Gradual Typing
Andrew P Black
black at cs.pdx.edu
Mon Jul 22 12:00:45 PDT 2013
I was going to propose something a little different.
Michael pointed out that a type-checker might prohibit
> 1 object {
> 2 method x -> Done {
> 3 self.y
> self.z
> 4 }
> 5 }
on the grounds that self doesn't have a y method. To make it clear that this is intentional, we need to use an annotation to keep the type checker happy. I propose
> 1 object is requiring(y, z) {
> 2 method x -> Done {
> 3 self.y
> self.z
> 4 }
> 5 }
The point is that we annotate the object constructor to say that we know that this object needs more methods before it is useful as a standalone object, and list their names. Of corse, I expect that an IDE will tell me that I need this annotation, and offer to put it there, as does Eclipse/Java with import statements.
I admit that "is requiring" sounds a bit like Bombay English. If we follow James' suggestion that we use colon for all annotation, including type annotation, then we could write
object: requires(y,z) {
which is a lot better.
I prefer this to declaring abstract methods because it lists, in one place, in a compact form, all the methods an inheritor needs to provide.
Andrew
More information about the Grace-core
mailing list