What is Newton
Newton is a new language being developed. It is not ready to be released yet, but I will use this site to keep friends and interested parties up to date.
Why a new language
I created Newton because I wanted to make a commercial desktop app and was not satisfied with the languages available. I needed native performance, static typing, and compilation to standalone executables; but it should also be as fast and pleasant to work in as Python.
Why Newton
The following features are currently supported:
- Static typing
- Hindley-Milner type inference
- Algebraic data types
- Structural pattern matching
- Function overloading
Some examples will be good to clarify how they are used in Newton:
Examples
Type Inference
def add(a, b):
return a + b + 1
Explicit type parameters
def identity[A](arg: A) -> A
return arg
The Maybe type from Haskell
variant Maybe[A]:
| Just(A)
| Nothing
Pattern matching
match optional_quantity:
case Just(qty):
return qty
case Nothing:
return 0
Very similar to the syntax in Python 3.
Function overloading
def plus(left: Int, right: Int) -> Int:
return primitive_add_i64(left, right)
def plus(left: Float, right: Float) -> Float:
return primitive_add_f64(left, right)
All instances of an overloaded function must:
- have the same arity
- have a different type in the first parameter
- return a monotype
Overloaded functions can be called with polymorphic arguments. Type errors will still be caught statically.
Current state
The compiler is implemented in Python and transpiling to Python. This way I can replace parts of the compiler with Newton piece by piece and bootstrap it gradually.
Medium term plans
- Records
- Compilation to a low-level target such as C, LLVM, WASM or machine code
- Perceus reference counting
Long term plans
- Classes (row polymorphism)
Design Goals
- High productivity
- Simple semantics that can be compiled efficiently
- Predictable run time behavior (strict evaluation, AOT compilation, reference counting)
- Look familiar to Python programmers
Stefan