-
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
Release agda2hs 1.3 #366
Comments
I've uploaded a release candidate to https://hackage.haskell.org/package/agda2hs-1.3/candidate It would be great if people could give it a test run (perhaps @omelkonian @HeinrichApfelmus @anka-213). If there are no complaints I'll do a proper release next week. |
Do you have a git commit (hash) that this release corresponds to? I need to test the combination of |
It should correspond to 770f209 |
I think that's the case, indeed. I'm not sure if there's an easy way to release the library also on Hackage, do you think it's worth investigating or is it fine to just distribute it via github? |
Distribution via Github, specifically the For a "proper" release that is accessible to a larger audience than just me, I think that investing time into creating release artifacts is unavoidable. I suppose that
would do the trick. More generally, in order to make |
I can definitely add the library to the Perhaps an alternative would be to provide a simple executable that sets up a new |
I installed locally (using cabal) and everything works fine, including using the |
Fair enough, I agree. Though, since
The main difficulty is to bring the agda2hs library in scope — only But the I personally don't like generated project templates, it's not modular enough for my taste. I would use it to find the location of the library, and then delete the rest of the generated project. 😅 |
That also seems a lot more feasible, so I'm all in favor. |
In order to test out However, I ran into an unexpected issue: I have a type record PairMap (a b v : Set) {{orda : Ord a}} {{ordb : Ord b}} : Set where
field
mab : Map a (Map b v)
mba : Map b (Map a v)
@0 invariant-equal
: ∀ (x : a) (y : b)
→ lookup2 x y mab ≡ lookup2 y x mba In order to formulate the invariant, I needed to constrain the type parameters However, agda2hs version 1.3 now gives me an error message when compiling:
How to proceed? I have tried moving the instance arguments to the definition of No instance of type Monad _m_2920 was found in scope.
- iMonadMaybe was ruled out because
/Users/hgz/Documents/MeineDokumente/Programmierung/Haskell/Work/cardano-wallet-agda/lib/customer-deposit-wallet-pure/agda/Haskell/Data/Maps/PairMap.agda:425,15-60
Cannot instantiate the metavariable _2870 to solution ordb
since it contains the variable ordb
which is not in scope of the metavariable
when checking that the inferred type of an application
(iMonadMaybe Monad.>>= Map.lookup y Map.empty)
(λ v₁ → Map.lookup x v₁)
≡ (iMonadMaybe Monad.>>= Nothing) (λ v₁ → Map.lookup x v₁)
matches the expected type
(iMonadMaybe Monad.>>= Map.lookup y Map.empty) (Map.lookup x) ≡
(_r_2921 Monad.>>= Nothing) (Map.lookup x) |
@HeinrichApfelmus The instance constraints data (Ord a, Ord b) => PairMap a b v = PairMap { mab :: Map a (Map b v)); mba :: (Map b (Map a v)) } Note that this is only valid with the deprecated In previous versions of record PairMap (a b v : Set) {{@0 orda : Ord a}} {{@0 ordb : Ord b}} : Set where ... |
Thank you, the erasure annotations are exactly what I need, indeed. 🙏 The use case is worth keeping in mind: Even though the computational parts of the data type do not depend on the type class, the (erased) invariants can only be expressed with the type class constraints. |
I have another issue: The following module module Test where
open import Haskell.Prelude
test : Integer
test = fromMaybe 0 (Just 12)
{-# COMPILE AGDA2HS test #-} is transpiled to module Test where
test :: Integer
test = fromMaybe 0 (Just 12) but this module does not compile — it's missing a line import Data.Maybe (fromMaybe) In other words, the function |
I also have an issue where a type class is transpiled as an ordinary argument. 🤔 Specifically, consider the following definition: Byron = ⊤
postulate
IsEra : Set → Set
instance
iIsEraByron : IsEra Byron The intention is that the class In agda2hs-1.2, the definition -- adga2hs-1.2
utxoFromTxOutputs : ∀{era} → {{IsEra era}} → Read.Tx era → UTxO
utxoFromTxOutputs = utxoFromEraTx was happily transpiled to -- adga2hs-1.3
utxoFromTxOutputs :: IsEra era => Tx era -> UTxO
utxoFromTxOutputs = utxoFromEraTx However, in agda2hs-1.3, this definition is transpiled to utxoFromTxOutputs :: IsEra era -> Tx era -> UTxO
utxoFromTxOutputs x = utxoFromEraTx x which the Haskell compiler will not accept, because EDIT: It looks like defining |
Indeed, it's actually a design pattern that shows up in the very first example in the documentation! 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
Good catch, related issue to #245.
Also a good catch! Since #284 we do check if the type of the instance argument is compiled to a class or not, and if not it is added as a regular argument. Maybe we should then add a specific compile pragma for postulated type formers that says "this is actually a Haskell class". Will open an issue for that. |
Yes, please. This issue is currently preventing me from upgrading my codebase to agda2hs-1.3. 😅 |
Wait, now that I think about it we already have the following pragma: {-# COMPILE AGDA2HS IsEra existing-class #-} used extensively in the prelude to avoid compiling the records. |
Unfortunately, it does not appear to work on |
One last thing that I noticed: I have two definitions member
: ∀ {time} {{_ : Ord time}}
→ time → RollbackWindow time → Bool
member time w = (finality w <= time) && (time <= tip w)
prune
: ∀ {time} {{_ : Ord time}}
→ time → RollbackWindow time → Maybe (RollbackWindow time)
prune newFinality w =
if member newFinality w
then (λ {{cond}} → Just (record
{ tip = tip w
; finality = newFinality
; invariant = projr (prop-&&-⋀ cond)
}))
else Nothing in my codebase. Strangely, the definition of prune newFinality w =
if finality w <= newFinality && newFinality <= tip w
then Just (RollbackWindowC newFinality (tip w))
else Nothing instead of prune newFinality w =
if member newFinality w
then Just (RollbackWindowC newFinality (tip w))
else Nothing In other words, the application of |
Right, the culprit here seems to be this line: agda2hs/src/Agda2Hs/Compile/Utils.hs Line 170 in 0412c42
Where we require
Could you show the compile pragmas you used for |
Assuming that you didn't use a |
I didn't enable any pragmas. The following appears to be a minimal test case: ./agda/Test.agda {-# OPTIONS --erasure #-}
module Test where
open import Haskell.Prelude
{-----------------------------------------------------------------------------
RollbackWindow
------------------------------------------------------------------------------}
record RollbackWindow (time : Set) : Set where
constructor RollbackWindowC
field
finality : time
tip : time
open RollbackWindow public
member
: ∀ {time} {{_ : Ord time}}
→ time → RollbackWindow time → Bool
member time w = (finality w <= time) && (time <= tip w)
prune
: ∀ {time} {{_ : Ord time}}
→ time → RollbackWindow time → Maybe (RollbackWindow time)
prune newFinality w =
if member newFinality w
then (λ {{cond}} → Just (record
{ tip = tip w
; finality = newFinality
}))
else Nothing
{-# COMPILE AGDA2HS RollbackWindow #-}
{-# COMPILE AGDA2HS member #-}
{-# COMPILE AGDA2HS prune #-} ./mylib.agda-lib
and then the invocation
will produce the file ./agda/Test.hs module Test where
data RollbackWindow time = RollbackWindowC{finality :: time,
tip :: time}
member :: Ord time => time -> RollbackWindow time -> Bool
member time w = finality w <= time && time <= tip w
prune ::
Ord time =>
time -> RollbackWindow time -> Maybe (RollbackWindow time)
prune newFinality w
= if finality w <= newFinality && newFinality <= tip w then
Just (RollbackWindowC newFinality (tip w)) else Nothing where the function I noticed that removing the type variable |
Thank you for the report, I've investigated it and created a new issue in #376. For now, it can be worked around by disabling the projection-likeness optimization with the |
I've updated the release candidate at https://hackage.haskell.org/package/agda2hs-1.3/candidate to correspond to the current master (afb5392). Since none of the remaining issues are critical, I plan to release this version tomorrow. |
Sounds good to me, thank you! |
Agda2hs 1.3 has now been officially released! https://hackage.haskell.org/package/agda2hs-1.3 |
It seems like we're long overdue for a new release (as indicated by the comment by @HeinrichApfelmus in #361 (comment)_).
One thing that might be worth doing is to investigate some lower/upper bounds on the dependencies (see e.g. #347 and #350 (comment)).
The text was updated successfully, but these errors were encountered: