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 absence of annotations to the type system when achieving both of the above

Neut doesn't use GCs or regions. Instead, it takes a type-directed approach to handle resources.

How Does it Look?

Like below:

// the obligated hello world
define hello(): unit {
  print("Hello, world!\n")
}

// algebraic data types (tau = the type of types)
data my-list(a: tau) {
| Nil
| Cons(a, my-list(a))
}

// a recursive function with pattern matching
define noisy-length(a: tau, 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(a, 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 will happen:

// (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, see How to Execute Types.

You may wonder: "So we need to, for example, copy the whole list just to get its length? Isn't it the end of the world?". This topic is covered in Static Memory Management. As written there, those redundant copyings can be avoided via something like "borrowing" in Rust. The idea is to add a new type &a, the noema type of a, which is the same as a except that it isn't discarded/copied, and to utilize it like a reference in the great ST monad.

How Fast is This?

Please see the benchmarks.

List of Other Basic Characteristics?

  • Call by value
  • Impure
  • Compiles to LLVM IR and binary
  • The type system ≒ CoC + ADT + (fix) - (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

Anything Else?

You might also find Neut's module system interesting. It distinguishes modules using the digests (checksums) of tarballs and defines module identities using version information. Although this is not the main point of the language, it still might be of interest. This topic is covered in the tutorial.

Also, Neut includes an LSP server, which provides things like code completion, error reporting on save, etc. See Lovely LSP Showcase to see it in action.


You can press the "→" key to go to the next page.