2018-12-29 18:48:21 +01:00
|
|
|
# `dhall`
|
2018-10-29 01:32:51 +01:00
|
|
|
|
2018-12-10 21:28:19 +01:00
|
|
|
For installation or development instructions, see:
|
|
|
|
|
|
|
|
* [`dhall-haskell` - `README`](https://github.com/dhall-lang/dhall-haskell/blob/master/README.md)
|
|
|
|
|
2018-12-13 15:44:33 +01:00
|
|
|
Full documentation here:
|
|
|
|
|
|
|
|
* [`dhall` instructions](https://hackage.haskell.org/package/dhall/docs/Dhall-Tutorial.html)
|
|
|
|
|
2018-12-10 21:28:19 +01:00
|
|
|
## Introduction
|
|
|
|
|
2018-10-29 01:32:51 +01:00
|
|
|
Dhall is a programmable configuration language that is not Turing-complete
|
|
|
|
|
|
|
|
You can think of Dhall as: JSON + functions + types + imports
|
|
|
|
|
|
|
|
## Motivation
|
|
|
|
|
|
|
|
*"Why not configure my program using JSON or YAML?"*
|
|
|
|
|
|
|
|
JSON or YAML are suitable for small configuration files, but larger
|
|
|
|
configuration files with complex schemas require programming language features
|
|
|
|
to reduce repetition. Otherwise, the repetitive configuration files become
|
|
|
|
error-prone and difficult to maintain/migrate.
|
|
|
|
|
|
|
|
This post explains in more detail the motivation behind programmable
|
|
|
|
configuration files:
|
|
|
|
|
|
|
|
* [Programmable configuration files](https://github.com/dhall-lang/dhall-lang/wiki/Programmable-configuration-files)
|
|
|
|
|
|
|
|
*"Why not configure my program using Haskell code?"*
|
|
|
|
|
|
|
|
You probably don't want to rebuild your program every time you make a
|
|
|
|
configuration change. Recompilation is slow and requires the GHC toolchain
|
|
|
|
to be installed anywhere you want to make configuration changes.
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
## Example
|
2018-10-29 01:32:51 +01:00
|
|
|
|
|
|
|
Given this Haskell program saved to `example.hs`:
|
|
|
|
|
|
|
|
```haskell
|
|
|
|
-- example.hs
|
|
|
|
|
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
import Dhall
|
|
|
|
|
|
|
|
data Example = Example { foo :: Integer, bar :: Vector Double }
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
2019-10-19 05:24:49 +02:00
|
|
|
instance FromDhall Example
|
2018-10-29 01:32:51 +01:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
x <- input auto "./config"
|
|
|
|
print (x :: Example)
|
|
|
|
```
|
|
|
|
|
|
|
|
... which reads in this configuration file:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ cat ./config
|
|
|
|
{ foo = 1
|
|
|
|
, bar = ./bar
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
... which in turn references this other file:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ cat ./bar
|
|
|
|
[3.0, 4.0, 5.0]
|
|
|
|
```
|
|
|
|
|
|
|
|
... you can interpret the Haskell program like this:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ nix-shell ../nix/test-dhall.nix
|
|
|
|
[nix-shell]$ runghc example.hs
|
|
|
|
Example {foo = 1, bar = [3.0,4.0,5.0]}
|
|
|
|
```
|
|
|
|
|
|
|
|
You can also interpret Dhall programs directly using the installed command-line
|
|
|
|
compiler:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ dhall
|
|
|
|
List/head Double ./bar
|
|
|
|
<Ctrl-D>
|
|
|
|
Optional Double
|
|
|
|
|
|
|
|
Some 3.0
|
|
|
|
```
|
|
|
|
|
|
|
|
... and you can reference remote expressions or functions by their URL, too:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ dhall
|
|
|
|
let null = https://raw.githubusercontent.com/dhall-lang/Prelude/35deff0d41f2bf86c42089c6ca16665537f54d75/List/null
|
|
|
|
in null Double ./bar
|
|
|
|
<Ctrl-D>
|
|
|
|
Bool
|
|
|
|
|
|
|
|
False
|
|
|
|
```
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
Now go read the [Dhall tutorial][haskell-tutorial] to learn more.
|
2018-10-29 01:32:51 +01:00
|
|
|
|
2019-02-12 19:05:49 +01:00
|
|
|
## Standard-compatibility table
|
|
|
|
|
|
|
|
| Haskell package version | Supported standard version |
|
|
|
|
|-------------------------|----------------------------|
|
|
|
|
| `1.20.*` | `5.0.0` |
|
|
|
|
| `1.19.*` | `4.0.0` |
|
|
|
|
| `1.18.*` | `3.0.0` |
|
|
|
|
| `1.17.*` | `2.0.0` |
|
|
|
|
| `1.16.*` | `1.0.0` |
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
[haskell-tutorial]: https://hackage.haskell.org/package/dhall/docs/Dhall-Tutorial.html
|