NEP17 Type Inference - ghewgill/neon-lang GitHub Wiki
This proposal suggests removing required type specifications for variable declarations.
Motivation
Currently, types are required for all variable declarations. This causes code to become more cluttered than it probably needs to be:
LET length: Number := 5
LET name: String := "widget"
LET description: String := "\(name), \(length)"
All the type specifications (: Number
and : String
) are technically redundant because the type is obvious from the right hand side.
Proposal
This propsal makes type specifications optional for CONSTANT
, VAR
, and LET
statements. The above code sample would look like:
LET length := 5
LET name := "widget"
LET description := "\(name), \(length)"
Type specifications may still be provided if desired for clarity.
Type specifications still required in some cases
There are a few cases where type specifications are still required:
- Empty arrays or dictionaries:
VAR a := []
is not valid because there is no way to determine what the type of the array elements should be. - Pointers initialized to
NIL
: The statementVAR p := NIL
requires a type specification to specify what classp
points to. - Conversions to and from
Object
:LET obj := 5
infers thatobj
should be aNumber
. To convert to anObject
, useLET obj: Object := 5
.