polar

Getting Started

Polar is a statically typed language that compiles to JavaScript. This page is an overview of the docs and of what you need to start.

What is Polar?

Polar lets you write programs for Node and the browser with a type checker that catches mistakes before your code runs. A few ideas set it apart:

  • Records that fit any shape. A function can ask for just the fields it reads, and accept any record that has them.
  • Effects in the type. A function's signature says whether it touches the outside world, like the DOM, a database or the clock. Pure functions stay pure, and the compiler checks it.
  • Hosts. One program can target the browser and the server. Polar works out where each function can run, and writes one bundle per host.
  • Plain JavaScript out. The output is readable ES modules, with source maps and .d.ts files, so it fits into existing projects.

Try Polar

Install the latest release. You need Node.js to run the JavaScript Polar writes, and Rust if your project uses zone plugins.

$ curl -fsSL https://polar-lang.vercel.app/install.sh | sh

This puts polar in ~/.polar/bin. Set POLAR_VERSION=0.1.0 to pick a version. To build from source instead, you need Rust 1.85 or newer:

$ git clone https://github.com/stepanvanzuriak/polar
$ cd polar
$ cargo install --path cli

This builds the compiler and puts the polar command on your PATH. Check that it worked:

$ polar --version

Tip: If you only want to try things out, cargo build also works. The compiler ends up at target/debug/polar, and you can run it from there.

Learn Polar

People come to Polar from different backgrounds, so these docs give you two ways in.

  • If you like to learn concepts step by step, start with Hello World and read the Main Concepts pages in order. Each one builds on the last.
  • If you prefer to learn by doing, jump to Thinking in Polar. It builds a small command-line program from scratch, and links back to the concepts as it uses them.

The docs are split into four groups, listed in the sidebar:

Note: Every example in these docs is checked against the current compiler. Outputs and error messages are copied from real runs.

What you should know first

The docs assume you've written some JavaScript or TypeScript. You don't need experience with typed functional languages: we'll explain types, pattern matching and effects as we meet them.

Ready? Let's start with Hello World.