Closed DylanSp closed 4 years ago
Type check pass should validate, not parse: returns Either<TypeError, Type>
where the Right
case represents the type of the top-level function. Evaluation still takes an AST from the parser.
Roughly following TS, could use
function makeAdder(x: number): (number => number) {
function adder(y: number): number {
return x + y;
}
return adder;
}
function doubleApply(func: (number => number), x: number): number {
return func(func(x));
}
Do I want to allow (parametric) polymorphism?
When adding type syntax, convert existing parser tests to use .toMatchObject(), so existing tests won't break as I add type-related properties.
Lack of separate declaration and assignment could cause problems.
x = 1;
x = x + 1;
Should line 2 have a type annotation, even if it's reusing already-declared variable?
Instead of adding syntax: type inference everything? Would probably need to drop polymorphism, but I can live with that.
If I go the inference route - how to handle ==
, /=
(and print
if I add that)? They're ad-hoc polymorphic.
Rather than full Hindley-Milner inference - treat it as a dataflow/DAG, and run the type checks one way. If I require initialization of variables to a value, which sets the variable's type permanently, I should just be able to work forwards through the DAG of statements/expressions.
Three options so far.
Option 1: usual C-style typing, explicit type annotations on everything.
Option 2: Hindley-Milner inference
Option 3: Forward-only dataflow analysis
I'm thinking that I'll leave wheel-lang dynamically typed, especially with exploring prototypical inheritance as syntax sugar.
Syntax similar to Typescript:
But how to do syntax for higher-order functions?