[Grace-core] Typed Imports

James Noble kjx at ecs.vuw.ac.nz
Wed Nov 21 21:32:46 PST 2012


Another smallish idea I don't want to forget.

Just as you can write "def A = b"  to get local type inference,  and "def A : T = e"  to declare with a manifest type,
as well as  "import "foo" as A" to declare foo via local type inference, we should support "import "foo" as A : T"
to import foo bound to A but with static type T.  If it turns out foo doesn't satisfy type T, we raise a compile time
or bind-time error.   This gets flexibility from structural typing for modules -- that T could come from a different
module:

 import "stackSpec" as StackSpec
 import "stackImpl" as StackImpl : StackSpec 

or even inline

type StackType = {
 push(Object)
 pop -> Object
}

import "stackImpl" as StackImpl : StackType   // almost! 

Should the stackImpl module change under the current program, that change can be caught statically

J





More information about the Grace-core mailing list