Skip to content
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

Skipping erased value arguments inside type functions in datatype parameters and in type lambdas #195

Merged

Conversation

viktorcsimma
Copy link
Contributor

@viktorcsimma viktorcsimma commented Jul 26, 2023

When giving type parameters to a record and using a dependent function which, however, has its value parameters erased; I've originally got an error (Kind of bound argument not supported). This PR fixes that.

The specific example (used in the test case, too):

open import Agda.Primitive

-- A record type which has both members compiled,
-- but the argument of the lambda is erased;
-- so that it won't be dependent-typed after compilation.
record Σ' {i j} (a : Set i) (b : @0 a  Set j) : Set (i ⊔ j) where
  constructor _:^:_
  field
    proj₁ : a
    proj₂ : b proj₁
open Σ' public
infixr 4 _:^:_
{-# COMPILE AGDA2HS Σ' #-}

The output here is

data Σ' a b = (:^:){proj₁ :: a, proj₂ :: b}

Update: now the arguments of type lambdas are also checked and if they are erased, they are dropped, instead of invoking an error. An example:

-- Actually, Agda can deduce here that n is erased; probably from the type signature of Σ'.
test : Nat -> Σ' Nat (λ (n : Nat) -> ⊤)
test n = n :^: tt
{-# COMPILE AGDA2HS test #-}

This produces an output like this:

test :: Natural -> Σ' Natural ()
test n = n :^: ()

@viktorcsimma viktorcsimma marked this pull request as draft July 26, 2023 12:05
@viktorcsimma
Copy link
Contributor Author

It now seems like that it compiles, but cannot be used... I'll try to fix that.

@viktorcsimma
Copy link
Contributor Author

Now it's OK:) I've inserted a similar check at type lambdas. See the update above.

@viktorcsimma viktorcsimma changed the title Skipping erased value arguments inside type functions in record parameter Skipping erased value arguments inside type functions in datatype parameters and in type lambdas Jul 26, 2023
@viktorcsimma viktorcsimma marked this pull request as ready for review July 26, 2023 12:46
src/Agda2Hs/Compile/Type.hs Outdated Show resolved Hide resolved
src/Agda2Hs/Compile/Type.hs Outdated Show resolved Hide resolved
src/Agda2Hs/Compile/Type.hs Outdated Show resolved Hide resolved
@viktorcsimma
Copy link
Contributor Author

One more thing apart from the comments: Type.hs has some more references to usableModality; should we change them to keepArg too? Or is there a reason why they are used there?

@jespercockx
Copy link
Member

One more thing apart from the comments: Type.hs has some more references to usableModality; should we change them to keepArg too? Or is there a reason why they are used there?

For types it is a bit more tricky since there is the possibility of an instance argument. These can be erased at the term level, but at the type level they need to be made into a constraint. So I don't think anything there should change.

@jespercockx jespercockx merged commit 4a9a614 into agda:master Jul 27, 2023
6 checks passed
@viktorcsimma viktorcsimma deleted the erased-arguments-in-type-functions branch August 9, 2023 08:40
@jespercockx jespercockx added this to the 1.1 milestone Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants