Hi everyone,
I would like to share a project I have been working on for a while: Haskue, an experimental Haskell implementation of part of the CUE configuration language.
- Try it online — it runs as WebAssembly, so no installation is needed
- GitHub repository
CUE is a configuration language based on constraints and unification.
I started Haskue partly to develop my Haskell skills further through a larger and more challenging project. I was also interested in the similarities between CUE’s value lattice and Haskell’s type system, even though they work differently. I wanted to explore how CUE’s evaluation model could be implemented in Haskell and make it easier to understand why evaluation produces a certain result.
For example:
database: {
host: string
port: >=1 & <=65535
}
database: {
host: "db.example.com"
port: 5432
}
Haskue combines these declarations into one value. It can also explain which constraints produced a result:
haskue eval example.cue -e database.port --explain
database.port = 5432
Conjuncts:
├─ >=1 example.cue:3:9
├─ <=65535 example.cue:3:15
└─ 5432 example.cue:7:9
One important influence on the evaluator was Build Systems à la Carte, written by Andrey Mokhov, Neil Mitchell, and Simon Peyton Jones. The paper says:
Excel is a build system in disguise.
This idea also helped me understand CUE. A value node is similar to a build target, constraints decide its result, and references form a dependency graph. Some reference targets are only known after other values are evaluated, so Haskue builds and updates this graph during evaluation. From this point of view, CUE can also be seen as a build system in disguise.
The evaluator takes ideas from both Excel and Shake. If a dependency is not ready, Haskue can try the evaluation again later. It can also handle some reference cycles and avoid more work when a value has not changed.
Haskue can export results as CUE, JSON, or YAML. It is still experimental rather than a drop-in replacement for the official CUE implementation; the current limitations are documented in the README.
I would be happy to hear your feedback.
Thanks for taking a look!