[Grace-core] Should Grace abandon "gradual typing" for "like typing"?

James Noble kjx at ecs.vuw.ac.nz
Wed Jul 27 10:17:03 PDT 2016


> On 28/07/2016, at 5:02AM, Andrew P. Black <black at cs.pdx.edu> wrote:
> 
> The object generated by the above code has dynamic type 
> 
> 	interface {
> 		x -> Boolean
> 	}

No, it has type

> 	interface {
> 		x -> Unknown
> 	}

because the declaration of "if" has no declared return type.
more simply, given the definition

method min(a, b) {
    if (a < b) then { a } else { b }
}

then any def (or indeed anything) that gets the value of min will have the Unknown (dynamic) type.  We could do a bit better by writing:

method min[[T]](a : T, b : T) -> T {
    if (a < b) then { a } else { b }
}

but if we call it as "min(1,2)" the resulting type is again Unknown.
To get a return type of Number we'd have to write "min[[Number]](1,2)"
We can statically infer that x should have type "Number", say,
but at that point type inference is changing the behaviour of the program:
the type inference algorithm is changing the dynamic types of objects in the program.  

James




More information about the Grace-core mailing list