ballercat / walt

:zap: Walt is a JavaScript-like syntax for WebAssembly text format :zap:
https://ballercat.github.io/walt/
MIT License
4.64k stars 122 forks source link

Type inference #143

Open piranna opened 6 years ago

piranna commented 6 years ago

Feature Request

Overview

Add support for type inference, so walt itself can discover the type of a variable from the values it's being assigned. For safety and simplicity this can be done in a strict way, don't allowing to change the type of a variable. This is something similar to how Rust types works. In a next iteration it would be changed to create new hidden variables transparently to the user if the type is different.

Impact

Medium. The most difficult part would be the type inference, but following the AST would not be too much difficult.

Details

This would allow to write more Javascript-like code, in most cases types would only be needed to be set in the function signature.

jarble commented 4 years ago

This has already been done in AssemblyScript, which compiles a variant of TypeScript to WebAssembly. Walt's syntax is very similar (if not identical) to AssemblyScript, so type inference is probably feasible.