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,matchtakes it apartdefercleans up on every way out
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
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@asynctoo
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
matchon cases, types, fields, tuples and errors
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, throughNumericandComparable- Vectors, matrices, complex numbers and quaternions built in
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
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 aResponse - Tests inject a
Requestand call the route directly - Components re-render when their
@statechanges - Compiled to WebAssembly - built for the browser first, and run by WASI runtimes too
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@json a definition, with--compile --js, gives a loader and its.d.mts- A JavaScript exception comes back as an ordinary error
- Without
--jsthe module stays plain WASI, for servers and native builds
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.
Word Count
Files, regular expressions and maps - tested on an in-memory file system.
HTTP Server
A todo API from a handful of annotated functions.
Webapp
Components with state, rendered in the browser.
Invoice Totals
Exact money in Refingere, formatting from TypeScript - and called from it.
Markdown Parser
Enums, pattern matching and HTML output.
Library Catalogue
Tables queried like SQL, with a fixed clock in the tests.
Metro Routes
Shortest paths on the builtin graph type.
Fractals
Complex numbers drawn as text, as an image, and on the GPU.
Starfall
A small game in the browser, its rules tested without a GPU.
Concurrent Jobs
Async jobs in lanes, timed to the second by a fixed clock.
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.