Neut Programming Language
Neut is a functional programming language with static memory management.
Its key features include:
- Full λ-calculus support
- Predictable automatic memory management
- The ability to achieve both of the above without extra type annotations
Neut doesn't use a GC. Instead, it takes a type-directed approach for memory management.
What Does it Look Like?
Like the following:
// the obligatory hello world
define hello(): unit {
print("Hello, world!\n")
}
// an algebraic data type
data my-list(a) {
| Nil
| Cons(a, my-list(a))
}
// a recursive function with pattern matching
define noisy-length<a>(xs: my-list(a)): int {
match xs {
| Nil =>
0
| Cons(_, ys) =>
let my-message = "hey\n" in
print(my-message);
add-int(1, noisy-length(ys))
}
}
Static Memory Management — But How?
Neut translates a type into a function that can discard/copy the values of the type. By using those functions, the compiler translates programs so that every variable is used exactly once.
For example, if a variable is used twice, a translation like the following happens:
// (before)
let xs: list(a) = [value-1, value-2] in
some-func(xs, xs) // `xs` is used twice
// ↓
// (after)
let xs: list(a) = [value-1, value-2] in
let (xs1, xs2) = copy-list-a(xs) in // `xs` is used once
some-func(xs1, xs2)
If you need more information, see How to Execute Types.
You might wonder: "So do I have to, for example, copy an entire list just to get its length? Isn't that a tragedy?". This topic is covered in Static Memory Management and Modality and Memory. As written there, Neut avoids such copy operations by using the box modality, achieving something like borrowing in Rust.
Quick List of Other Features
- Call by value
- Impure
- Compiles to LLVM IR and binary
- The type system ≒ CoC + ADT + (recursion) + (T-necessity) - (universe hierarchy)
- That is, the usual one in functional programming, but a bit generalized
- Built-in LSP support
- Built-in rapid prototyping experience like scripting languages
- Built-in formatter like Go
You can press the "→" key to go to the next page.