-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support for wrapping Haskell modules via postulate
#316
Comments
Could you explain how this would be different from the existing support for declaring agda2hs rewrite rules in a separate file? (see https://agda.github.io/agda2hs/features.html#rewrite-rules-and-prelude-imports) I think the idea here is solid, but I'd prefer to avoid reinventing the wheel. |
Sure. First, the intended use case is different. According to the documentation, Rewrite rules and Prelude imports, are "particularly useful if you have a project depending on a large library which is not agda2hs-compatible (e.g the standard library)." That's not the intended use case here — instead of making Agda data types that have concrete definitions, e.g. But a difference of use cases does not yet imply that the feature is not suitable for the other use case as well. However, I believe that the following differences are good reasons to add a
Now that you mention it, there is some overlap, though. 🤔 Specifically, consider the following example: postulate
empty : Map k a
insert : k → a → Map k a → Map k a
singleton : k → a → Map k a
singleton = λ k x → insert k x empty The functions |
Problem statement
The mission statement of Adga2hs is to carve out a sublanguage of Agda that translates directly to Haskell, so that we can prove properties about Haskell-in-Agda programs in Agda. This is highly useful for producing high assurance Haskell code. Personally, I think of Agda2hs as "the missing proof assistant for Haskell".
I particularly enjoy that Agda2hs allows me to develop proofs about Haskell programs in an incremental fashion: I can write and prove selected parts of my program in Haskell-in-Agda, export them to Haskell, and use the result together with existing Haskell code that was only tested, not proven.
However, I feel that this incremental approach would become even more powerful if Agda2hs better supported the import of Haskell code. Here, I don't mean a syntactic import of Haskell code (that would be amenable to proof), but an import of Haskell functions and "tested" properties via Agda's
postulate
mechanism. Let me call this "wrapping a Haskell module".Put differently, at the moment, Agda2hs implements a translation from
.agda
to.hs
files where the.agda
file is the "source of truth". I would like to see a translation from.agda
to.hs
where the.hs
file acts as a "source of truth".Proposed solution:
COMPILE … IMPORT
pragmaAgda2hs has made a design decision to translate
.agda
files to.hs
files. In particular, it does not attempt to parse Haskell files. This design works particularly well for using Agda2hs as a preprocessor for Haskell. In order to explore this point in the design space properly, we need to take it to its logical extreme before changing it. Hence, I'll leave the Haskell to the Haskell compiler.Consider the following module, which is legal Adga2hs today:
(This is a real world example.) This module defines two data types
XPub
andXPrv
and a functiontoXPub
. However, instead of giving an actual definition, this module simply postulates the identifiers and emits Haskell code that imports the identifiers from the Haskell moduleCardano.Crypto.Wallet
.This module does what I want: I can use the Haskell
Cardano.Crypto.Wallet
in my Haskell-in-Agda code. By postulating properties, I can also do proofs (while assuming that the properties hold).However, this module would benefit from native support in Agda2hs. In particular, the following would be an improved version:
Here, the intention is that the new compiler pragma
{-# COMPILE AGDA2HS toXPub IMPORT #-}
compiles to a type signature and equation of identifiers
For types such as
XPub
andXPrv
, instead of defining a type synonym, the identifiers would be added to the export list.The name of the imported Haskell module is obtained by stripping the
Haskell
prefix from the Agda module name. For the purpose of disambiguation, the generated module keeps theHaskell
prefix.This level of native support in Agda2hs has the following advantages over the version using
FOREIGN AGDA2HS
:toXPub
twice.It's worth repeating that the decision to only emit Haskell code, but to never parse Haskell code is preserved.
What do you think?
The text was updated successfully, but these errors were encountered: