MorphicResearch Language

What is Morphic?

Morphic is an experimental pure functional programming language designed to achieve performance competitive with imperative systems languages like C++ and Rust.

Morphic features three automatic optimizations which turn functional programming constructs into zero-cost abstractions:

Lambdas

Morphic's lambda set specialization makes lambdas unboxed and statically dispatched, and allows calls to lambdas to be inlined.

Data Structures

Morphic's mutation optimization transforms updates to logically-immutable data structures into in-place mutations when doing so does not affect semantics.

Memory Management

Morphic uses a borrow-based reference counting scheme which is able to eliminate almost all reference count increments and decrements for a large class of programs.

Morphic in action

type Primality {
  Prime,
  Composite,
}

sieve(limit: Int): Array Primality =
  // Array memory is automatically managed statically,
  // without any refcounting overhead in this case.
  let init_arr =
    Array.fill(limit, Prime)
    |> Array.set(0, Composite)
    |> Array.set(1, Composite)
  in
  // Iterator logic compiles to a simple loop, with
  // no heap allocations or virtual dispatch.
  Iter.range(2, limit)
  |> Iter.foldl(init_arr, \(arr, n) ->
    match Array.get(arr, n) {
      Prime ->
        Iter.ints(2)
        |> Iter.map(\i -> i * n)
        |> Iter.take_while(\i -> i < limit)
        |> Iter.foldl(
          arr,
          // Array updates logically copy the array,
          // but are automatically performed in-place
          // when safe.
          \(new, i) -> Array.set(new, i, Composite)
        ),
      Composite -> arr,
    }
  )

Contributors

Benjamin Driscoll

bdrisc@cs.stanford.edu

PhD student at Stanford University researching programming languages and compilers. Bachelor's in CS and math from UC Berkeley.

William Brandon

wbrandon@csail.mit.edu

Engineer at Anthrophic. Former PhD student at MIT CSAIL researching programming languages, compilers, and deep learning. Bachelor's in CS and math from UC Berkeley.

Frank Dai

Independent type theory researcher. Bachelor's in CS and math from UC Berkeley.

Wilson Berkow

Senior GPU Compiler Engineer at Apple. Bachelor's in CS from UC Berkeley.

Mae Milano

Assistant professor at Princeton University working in programming language design for systems.