|
1 | 1 | # agda2hs Documentation
|
2 | 2 |
|
| 3 | +`agda2hs` is a tool for producing verified and readable Haskell code by |
| 4 | +extracting it from a (lightly annotated) Agda program. For example, |
| 5 | +the following Agda program encodes well-formed binary search trees: |
| 6 | + |
| 7 | +```agda |
| 8 | +open import Haskell.Prelude |
| 9 | +
|
| 10 | +_≤_ : {{Ord a}} → a → a → Set |
| 11 | +x ≤ y = (x <= y) ≡ True |
| 12 | +
|
| 13 | +data BST (a : Set) {{@0 _ : Ord a}} (@0 lower upper : a) : Set where |
| 14 | + Leaf : (@0 pf : lower ≤ upper) → BST a lower upper |
| 15 | + Node : (x : a) (l : BST a lower x) (r : BST a x upper) → BST a lower upper |
| 16 | +
|
| 17 | +{-# COMPILE AGDA2HS BST #-} |
| 18 | +``` |
| 19 | + |
| 20 | +agda2hs translates this to the following Haskell datatype: |
| 21 | + |
| 22 | +```haskell |
| 23 | +module BST where |
| 24 | + |
| 25 | +data BST a = Leaf |
| 26 | + | Node a (BST a) (BST a) |
| 27 | +``` |
| 28 | + |
| 29 | +`agda2hs` is intended to be used together with the provided `Haskell.Prelude` |
| 30 | +module, which provides an Agda implementation of (a large subset of) the Haskell |
| 31 | +Prelude. It also provides proofs for reasoning about Haskell functions under the |
| 32 | +`Haskell.Law` namespace. `agda2hs` is *not* compatible with other Agda libraries |
| 33 | +such as the Agda standard library. |
| 34 | + |
| 35 | +## Objective |
| 36 | + |
| 37 | +The goal of this project is *not* to translate arbitrary Agda code to Haskell. |
| 38 | +Rather it is to carve out a common sublanguage between Agda and Haskell, |
| 39 | +with a straightforward translation from the Agda side to the Haskell side. |
| 40 | +This lets you write your program in the Agda fragment, using full Agda |
| 41 | +to prove properties about it, and then translate it to nice looking readable |
| 42 | +Haskell code that you can show your Haskell colleagues without shame. |
| 43 | + |
| 44 | +If you want to compile arbitrary Agda programs to runnable (but not readable) |
| 45 | +Haskell, you should instead use the built-in |
| 46 | +[GHC backend of Agda](https://agda.readthedocs.io/en/v2.6.4/tools/compilers.html#ghc-backend) |
| 47 | +(a.k.a. MAlonzo). |
| 48 | + |
| 49 | +## Documentation |
| 50 | + |
| 51 | +The documentation you are currently reading is a work in progress, so if you |
| 52 | +have been using `agda2hs` and want to contribute in some way, adding |
| 53 | +documentation or examples would be very welcome. |
| 54 | + |
| 55 | +agda2hs was introduced in the Haskell Symposium '22 paper [Reasonable Agda is |
| 56 | +Correct Haskell: Writing Verified Haskell using |
| 57 | +agda2hs](https://jesper.sikanda.be/files/reasonable-agda-is-correct-haskell.pdf). |
| 58 | + |
| 59 | +## Future work |
| 60 | + |
| 61 | +Currently `agda2hs` is under active development, please take a look at the |
| 62 | +[issue tracker](https://github.com/agda/agda2hs/issues). If you have a |
| 63 | +suggestion for a new feature that is not yet on the issue tracker, you are |
| 64 | +welcome to create a new issue or a PR. Feature requests should be of the form |
| 65 | +"Add support for Haskell feature X", *not* "Add support for Agda feature Y" (see |
| 66 | +"Objective" above). If you want to compile arbitrary Agda code to Haskell, you |
| 67 | +are advised to use Agda's built-in GHC backend instead. |
| 68 | + |
| 69 | + |
3 | 70 | ```{toctree}
|
4 | 71 | ---
|
5 | 72 | maxdepth: 1
|
|
0 commit comments