Neut Programming Language

Neut is a functional programming language with static memory management.

Key Features

  • Full λ-calculus support
  • Predictable, type-directed memory management
  • No extra type annotations needed to achieve both of the above

Code Example

A typical program looks as follows:

// 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 foo<a>(xs: my-list(a)) -> int {
  match xs {
  | Nil =>
    0
  | Cons(_, ys) =>
    let my-message = "hey\n";
    print(my-message);
    add-int(1, foo(ys))
  }
}

Static Memory Management

Neut translates a type into a function for discarding and copying 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) = make-list();
some-func(xs, xs) // `xs` is used twice

// ↓

// (after)
let xs: list(a) = make-list();
let (xs1, xs2) = copy-list-a(xs);  // `xs` is used once
some-func(xs1, xs2)

If you need more information, see On Executing Types.

At this point, one concern is whether operations such as taking the length of a list require copying the entire value. Neut avoids such copy operations by using the box modality, achieving something like borrowing. See Static Memory Management and Modality and Memory for details.

Quick List of Other Features

  • Call-by-value
  • Impure
  • Compiles to LLVM IR and native binaries
  • The type system ≈ System Fω + ADT + recursion + box modality
    • That is, the usual one in functional programming, but a bit generalized
  • Built-in LSP support
  • Built-in rapid prototyping support as found in scripting languages
  • Built-in formatter

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