Library

The backend components (recalculation engine, server routing and language implementation) are decoupled and can readily be re-used.

Since there is only one actual frontend, the most common usage will be:

import Recalc.Univer

data Term = ...

instance Recalc Term where
  -- language semantics

instance UniverRecalc Term where
  -- error pretty-printing
  -- sheet-defined function handling (optional)

main :: IO ()
main = univerMain @Term env0

Recalc

The Recalc instance specifies how to

  • parse formulas and values (simple terms),
  • compute the dependencies of a term,
  • infer types given the type(s) of other cells (using fetchType),
  • and evaluate a term (again given the values of other cells, this time using fetchValue).

For type inference there are two functions that can be implented, either infer or inferElaborate (only one should be defined). The latter is for type-directed elaboration and during type inference terms may be refined.

UniverRecalc

The UniverRecalc instance specifies how to

  • display errors (by defining errorAnnotation),
  • and (optionally) how a sheet-defined function extends the environment.

For concrete implementations refer to engine tests, or the core language implementation (described here).


The TypeScript frontend currently is not in a library form, the easiest will be to run the original extension and configure the language server (by setting recalc-vscode.serverUri in your settings.json).