• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language Agda
  • License
    MIT License
  • Created about 4 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Compiling Agda code to readable Haskell

GitHub CI

agda2hs

Agda2hs is a tool for producing verified and readable Haskell code by extracting it from a (lightly annotated) Agda program. For example, the following Agda program encodes well-formed binary search trees:

open import Haskell.Prelude

_≤_ : {{Ord a}} → a → a → Set
x ≤ y = (x <= y) ≡ True

data BST (a : Set) {{@0 _ : Ord a}} (@0 lower upper : a) : Set where
  Leaf : (@0 pf : lower ≤ upper) → BST a lower upper
  Node : (x : a) (l : BST a lower x) (r : BST a x upper) → BST a lower upper

{-# COMPILE AGDA2HS BST #-}

agda2hs translates this to the following Haskell datatype:

module BST where

data BST a = Leaf
           | Node a (BST a) (BST a)

Objective

The goal of this project is not to translate arbitrary Agda code to Haskell. Rather it is to carve out a common sublanguage between Agda and Haskell, with a straightforward translation from the Agda side to the Haskell side. This lets you write your program in the Agda fragment, using full Agda to prove properties about it, and then translate it to nice looking readable Haskell code that you can show your Haskell colleagues without shame.

Documentation

Documentation can be viewed at https://agda.github.io/agda2hs. You can also find examples in the test directory of this repository, in particular the file Test.agda. The documentation is a work in progress, so if you have been using agda2hs and want to contribute in some way, adding documentation or examples would be very welcome.

agda2hs was introduced in the Haskell Symposium '22 paper Reasonable Agda is Correct Haskell: Writing Verified Haskell using agda2hs.

Future work

Currently agda2hs is under active development, please take a look at the issue tracker. If you have a suggestion for a new feature that is not yet on the issue tracker, you are welcome to create a new issue or a PR. Feature requests should be of the form "Add support for Haskell feature X", not "Add support for Agda feature Y" (see "Objective" above). If you want to compile arbitrary Agda code to Haskell, you are advised to use Agda's built-in GHC backend instead.

More Repositories

1

agda

Agda is a dependently typed programming language / interactive theorem prover.
Haskell
2,492
star
2

agda-stdlib

The Agda standard library
Agda
579
star
3

cubical

An experimental library for Cubical Agda
Agda
452
star
4

agda-categories

A new Categories library for Agda
Agda
367
star
5

agda-frp-js

ECMAScript back end for Functional Reactive Programming in Agda
Agda
103
star
6

agda-language-server

Language Server for Agda
Haskell
101
star
7

agda-frp-ltl

An implementation of Functional Reactive Programming
Agda
41
star
8

agda-ocaml

OCaml backend for Agda
Haskell
39
star
9

agda-pkg

apkg - package manager for Agda
Python
38
star
10

agda-spec

Specification of Agda.
TeX
25
star
11

agda-system-io

Bindings to Haskell's IO monad which respect Agda's semantics
Agda
24
star
12

agda-web-semantic

Agda libraries for the semantic web
Agda
23
star
13

ooAgda

Interactive and object-oriented programming in Agda using coinductive types
Agda
22
star
14

agda-finite-prover

Library for proving propositions quantified over finite sets
Agda
14
star
15

package-index

A package Index for agda libraries
12
star
16

categories-examples

Examples of categorical structures
Agda
11
star
17

agda-base

This is an experimental base library which is supposed to contain functional datastructures and reflection code.
Agda
10
star
18

agda-assoc-free

An implementation of "Associativity for Free"
9
star
19

fix-whitespace

Fixes whitespace issues
Haskell
8
star
20

hs-tags

Generate ctags and etags for Haskell files
Haskell
5
star
21

agda-makefile

An makefile with lightweight dependency management
5
star
22

guarded

Agda
5
star
23

agda-data-bindings

Agda bindings for low-level datatypes such as raw naturals and bytestrings
Agda
5
star
24

agda-web-uri

Simple bindings for parsing, processing and serializing URIs
Haskell
4
star
25

agda-github-syntax-highlighting

Syntax highlighting used on GitHub
Agda
4
star
26

agda-uhc

UHC backend for Agda
Haskell
4
star
27

agda-ghc-names

Tool for making sense of the Haskell code generated by the Agda compiler
Haskell
4
star
28

agda-text-xml

Simple bindings for parsing, processing and serializing XML
3
star