[Grace-core] Should Grace abandon "gradual typing" for "like typing"?
Vitek, Jan
j.vitek at northeastern.edu
Thu Jul 28 15:08:08 PDT 2016
> if I've got a like type such as
>
> type Fooable = like { foo } // something Fooable has a Foo method
>
> what happens if I assign an object that doesn't have a Foo method to that variable (and, say, never actually call the foo method). Presumably that object is flowing in e.g. from a variable or parameter of type Unknown (aka Dynamic)
> so we don''t know at compile-time (or type-check type) whether or not
> the object is Fooable...
>
> method assignToFooable( other : Unknown -> like Fooable {
> // now I'm being extra explicit other is dynamically typed
> def x : like Fooable = other
> return x
> }
>
> Does the assignment to a Fooable cause an error or not? (I guess I should read the formalsims, but...)
>
> I thought Dart in checked mode *would* raise a dynamic error there.
> I thought Thorn would too, and if we can be sure that other does
> not have a foo method we get an eager error…?
No error in Thorn, Dart (unchecked), TypeScript, Hack.
But if you remove the “like” annotation, there will be an error.
-j
More information about the Grace-core
mailing list