Allow to type symbols, not only variables

The proposal is to allow to type symbols, and not individual variables. A limited form of regular expressions (re) could be used.
for instance:

symbol n\d* : Int
symbol my-type- : type
def f(n) = n+n //n match the re n\d+, the compiler knows it's an Int.
def g(n1,n2) = n1+n2 //the compiler knows n1 and n2 are Int.
def f(myRect) = ... //myRect match the re my-type-, the compiler knows it's a Rect.

The scope of the symbol declaration is the usual scope for a declaration (“symbol” may not be the right keyword to use, and “-type-” may be different).
The intent is to mimic what is often seen in scientific papers: to indicate once and for all the set of the symbols used later.
A secondary intent is to be more pythonic.
Of course, variables can still be typed as usual, and it takes precedence over symbol declarations.

1 Like