Skip to content

Repository files navigation

Fortl - A language for descriptive and prescriptive scientific code

Fortl logo

Fortl is a programming language for scientific and numerical computing.

System principles/values. Code should enable:

  • Articulation of human scientific knowledge;
  • Expressing meaning, inntent, and limitations of scientific models;
  • Computation of predictions in a way that is repeatable, reusable, and reproducable and connected to more abstract descriptions.

How does this work out technically?

  • Statically-typed: say what you mean, enforce what you need
  • Graded numerical types: types are indexed and carry structure, allowing for domain-specific properties to be expressed (and enforced) in the type system;
  • Python-like syntax: lower barrier to entry

Example and usage

From examples/quantity.frtl:

"""
Simple example showing units and quantities
"""
x : Float[Unit[m] & Quantity[length]] = 2.0
y : Float[Unit[m] & Quantity[length]] = 1.0
t : Float[Unit[s] & Quantity[time]] = 4.0
# End result
it : Float[Unit[m / s] & Quantity[length / time]] = (x + y) / t

Running fortl examples/quantity.frtl produces:

Well-typed as Float[{(UoM & KoQ)}][(Unit[(m * s^-1.0)] & Quantity[(length * time^-1.0)])]
0.75

The type checker verifies the units and quantities are consistent, and evaluates the result (2.0 + 1.0) / 4.0 = 0.75 with inferred type Float[Unit[m/s] & Quantity[length/time]].

REPL

The interactive REPL (fortli) supports interactive evaluation and type inference. You can:

  • Evaluate an expression — type any expression and press Enter
  • Infer a type:t expr infers the type of an expression; :k type infers the kind of a type
  • Load a file:l path/to/file.frtl runs type inference on the file and loads its definitions into the environment
  • Get help:h lists all available commands
  • Quit:q

Example session:

% fortli
...
[F]> :l examples/units.frtl
Well-typed as Float[{UoM}][Unit[(M * S^-1.0)]]
0.25
units> x
1.0
units> :t x
Float[{UoM}][Unit[M]]
units> :k Float
{d : Descriptor} -> d -> Type

Building and Installing

Fortl is built with Stack.

Prerequisites: GHC 9.2.5 and Stack installed.

Build:

stack build

Run a file:

stack exec fortl -- <file.frtl>

Interactive REPL:

stack exec fortli

Install executables to your PATH:

stack install

After installing, fortl and fortli will be available as commands directly.

Background

fortl is based on ideas around using 'graded monoids' (due to McBride and Nordvall-Forsberg) appearing in this paper:

and early ideas we had about building languages for science, in this paper:

There are some similarities to F# but fortl's aim is to be much more general and flexible, going beyond units-of-measure.

Contributing

This project is in its early stages, but we would welcome any contributions, bug reports, or feature requests. Please start by raising an issue if you want to contribute or have a question.

About

A research language for scientific computation with a focus on making domain concepts first-class

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages