We want to implement a new language design. These are the following ideas:
Data Storage
We use primitive values like integers, floats and boolean's to represent values. Arrays are a repetition of a given value, struct a composition of different value types. Pointers are a reference to a value of a given type. Fat pointers are pointers combined with an index or length. For example, a string slice is a fat pointer that points to the start of the slice and contains the length of the slice.
struct Composition {
field1: f64,
field2: i32
}
let array = [0, 1, 1, 2, 3, 5, 8]
let value = 0
let pointer: *i32 = &value
Functions and Procedures
Functions:
- No side effects, therefore no mutability and no IO access
- Can only call other functions
- Contains only one single expression
- No loops, but support for if/then/else and let/in
- Support lazy evaluation and can be evaluated at compile time, if all arguments are known at compile time
Procedures:
- Side effects and IO access
- Can both call procedures and functions
- Contains a list of statements that will be sequential executed at runtime
Lambdas:
- Unnamed procedures
- Every lambda will be desugerated to create a new procedure with a auto-generated name
- The declaration of the lambda will be replaced with a function pointer to the generated procedure
- We will use name mangling like
module$file$lambda1
proc procedure(arg: Data): ReturnType {
# Statements
}
func function(arg: Data): ReturnType =
let
variables = ...
in
expression
Statements and Expressions
I don't think we will need to change much here. The if construct is already a expression. The let/in construct will most likely be implemented as a syntactic sugar for lazy evaluation.
Generics
I propose a very simple generic system that we can extend in the future with more features. Every struct/function/procedure lists all generic types at the start of the declaration. For every generic instance later used inside the code, a new struct/function/procedure where all generic types are replaced with the used types. For example, if we define the following function:
func id<T>(value: T): T = value
and call inside the code
then the following code will be generated:
func id$bool(value: bool): bool = value
Nice to Have
This is a list of features that are nice to have, but not needed to create a Turing complete language.
- Pattern matching for functions
- Impl and Traits for Structs
- Enums similar to Rust
- Module visibility modifiers
- Immutable by default, Mutable with
mut
- Life times
We want to implement a new language design. These are the following ideas:
Data Storage
We use primitive values like integers, floats and boolean's to represent values. Arrays are a repetition of a given value, struct a composition of different value types. Pointers are a reference to a value of a given type. Fat pointers are pointers combined with an index or length. For example, a string slice is a fat pointer that points to the start of the slice and contains the length of the slice.
Functions and Procedures
Functions:
Procedures:
Lambdas:
module$file$lambda1Statements and Expressions
I don't think we will need to change much here. The if construct is already a expression. The let/in construct will most likely be implemented as a syntactic sugar for lazy evaluation.
Generics
I propose a very simple generic system that we can extend in the future with more features. Every struct/function/procedure lists all generic types at the start of the declaration. For every generic instance later used inside the code, a new struct/function/procedure where all generic types are replaced with the used types. For example, if we define the following function:
and call inside the code
then the following code will be generated:
Nice to Have
This is a list of features that are nice to have, but not needed to create a Turing complete language.
mut