-
Notifications
You must be signed in to change notification settings - Fork 2
dynamic type usage
#dynamic type usage
Stability: 2 - Unstable
- Modules
- [type safety](type safety)
use types across promiseLand Modules.
##type variables
a type exists parallel as a compilation rule and as a type variable.
class type SomeType{};
var myType = SomeType; // refers to the type variable.
var a = new SomeType(); // generates a hard coded runtime exception and a compiler warning.
####achievement use type variables to communicate about types.
this is a example of a module that defines a type (lets name it "SomeType.pland"):
class type SomeType{
some: "member"
};
return SomeType;
this module requires the type. note that we can not yet use the type in this example.
var SomeType = require "SomeType";
SomeType someVar = new SomeType(); // generates a compiler error
the new Operator on a type variable results in undefined behavior.
promiseLand defines a new object notation syntax.
<{
member: expression
...
}>
the < > brackets were inspired by c++ templates. but the similarities end here.
use a template object to tell the compiler you want to use a type within a function.
<{
types: {
TypeName: typeVariable
}
}>function (){
TypeName a = new TypeName();
};
the function is compiled at runtime.
keep in mind, generating the function is slow, calling it is fast.
you can now use types in all your promiseLand modules.
var SomeTypeVariable = require "SomeType";
return <{
types: { SomeType: SomeTypeVariable }
}>(){
// you see, the type usage is pretty much a new module header
SomeType a = new SomeType();
}();
####achievement have a type available in all your modules
type mismatch are runtime errors. there are two reasons for this.
- consistency
dynamic type errors will only be known during runtime. - freedom
you may need to build a function that contains type errors that are never executed. a compile time error would restrain you to much in such scenarios.
you can also check for incompatibilities by catching runtime type errors.
Stability: 0 - Idea
there may be a compiler flag in the future to indicate weather or not you want to have compile time errors.
the template object could easily contain this information.
found any errors?
missing something?
let me know