Refingere Language

A statically typed language for web development first: the server, the browser app and the code they share, in one language and checked by one compiler. Errors are values, the outside world comes through a context you can replace, and what web programs need is built in. It compiles to WebAssembly and JavaScript, for the browser and the server alike.

Errors

Errors are values, not surprises

A function that can fail says so in its type, and the caller decides what to do - right where it's called. No exceptions flying past three stack frames.

  • !! passes an error up in two characters
  • !? gives a fallback, match takes it apart
  • defer cleans up on every way out
Learn more: Errors →

Context

Testable without changing a line

The clock, the file system, output, randomness and your own services are context values - read by name anywhere, provided by the caller for everything it calls.

  • No globals, no parameters threaded through every call
  • Tests inject a fixed clock, an in-memory file system, a fake mailer
  • One project-wide default, overridden per folder, test or request
Learn more: Context →

Async

Waiting that tests don't wait for

An @async function pauses at await and lets other work run meanwhile - one thread, no locks. Its timers go by the injected clock, so a fixed clock runs minutes of waiting in no time.

  • Start several calls, then await Promise.all
  • Errors travel in the value: await load()!!
  • @main, tests and routes can be @async too
Learn more: Async →

Types

Types built from parts

Structs, enums with data, interfaces and generics - and no inheritance. Types are combined, not extended, and match takes them apart.

  • && combines structs' fields, || enums' cases
  • Interfaces are implemented separately, even for builtin types
  • match on cases, types, fields, tuples and errors
Learn more: Types →

Notation

Code that reads like the formula

Roots, powers, subscripts and chained comparisons work as written, and your own types get the same operators by implementing an interface.

  • √x, x², xsᵢ, 0 ≤ x < n
  • +, * and < on your own types, through Numeric and Comparable
  • Vectors, matrices, complex numbers and quaternions built in
Learn more: Numbers →

Macros

Other languages, checked when you compile

SQL, HTML, CSS, JSON and regular expressions are written as themselves, checked by their own parsers, and turned into typed values.

  • A typo in the SQL is a compile error, pointing into the query
  • Values go in through #{ }, escaped for each language
  • Write your own macros, derives and attributes
Learn more: Macros →

Web

Servers and apps from plain functions

Attributes turn functions into HTTP routes and structs into browser components. The code stays ordinary, so tests call it directly.

  • The request is &request, the answer a Response
  • Tests inject a Request and call the route directly
  • Components re-render when their @state changes
  • Compiled to WebAssembly - built for the browser first, and run by WASI runtimes too
Learn more: Servers and Browser Apps →

JavaScript

Works with JavaScript and TypeScript

One attribute joins a function to JavaScript. Without a body, it's a JavaScript function Refingere calls; with one, it's a Refingere function JavaScript calls - values converted to the declared types on the way, both ways.

  • @js("./money.ts") on a declaration calls a module's export
  • @js on a definition, with --compile --js, gives a loader and its .d.mts
  • A JavaScript exception comes back as an ordinary error
  • Without --js the module stays plain WASI, for servers and native builds
Learn more: JavaScript and TypeScript →

Batteries included

Tables, graphs, linear algebra, dates and regular expressions are part of the language, so a program rarely starts by choosing libraries - and every example uses the same types.

Complete programs, with their tests

Every example is a whole program, explained step by step, with the tests that check it.

Running in a few minutes

1.Get the compiler - download it for your platform, one file, nothing else to install

2.Write a program

3.Run and test it

Or start from a template - a website with its logic in Refingere, or a program

See Websites.