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]].
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 exprinfers the type of an expression;:k typeinfers the kind of a type - Load a file —
:l path/to/file.frtlruns type inference on the file and loads its definitions into the environment - Get help —
:hlists 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 -> TypeFortl is built with Stack.
Prerequisites: GHC 9.2.5 and Stack installed.
Build:
stack buildRun a file:
stack exec fortl -- <file.frtl>Interactive REPL:
stack exec fortliInstall executables to your PATH:
stack installAfter installing, fortl and fortli will be available as commands directly.
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.
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.
