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

Support Nat literals #4

Open
flupe opened this issue Jan 24, 2025 · 0 comments
Open

Support Nat literals #4

flupe opened this issue Jan 24, 2025 · 0 comments
Labels
enhancement New feature or request icebox Things that won't happen soon

Comments

@flupe
Copy link
Collaborator

flupe commented Jan 24, 2025

Currently, Nat literals (when importing the builtin Agda.Builtin.Nat) in terms are desugared into the right sequence of constructor applications.

For patterns, the story is a bit different.

If the literal pattern is 0, then things work out and the pattern is replaced with the zero constructor patterns.

But for other literal Nat patterns, like 3, there's no direct translation to Lambox, as the case construct in Lambox only peels off one layer of constructors.

Two possible solutions:

  • There's the EliminateLiteralPatterns treeless transformation, which removes all literal patterns.
    See here.
    But it instead inserts a boolean check over a builtin equality over Nat (or other literals).
    So it requires a builtin ifThenElse and a builtin natEquality, which we don't have out of the box.

The backend could ask for those to be generated as axioms in the Lambox environment, to be supplied when compiling to different targets.

  • We could also try to replace a case n {3 -> ...} into successive case applications.

    case n {suc n' -> case n' {suc n'' -> case n'' {suc n'''} -> case n''' { zero -> ... }}}}}.

    However, this generates a lot of extra case branches.
    We need cases to be exhaustive.
    It's unsatisfying.

@flupe flupe added enhancement New feature or request icebox Things that won't happen soon labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request icebox Things that won't happen soon
Projects
None yet
Development

No branches or pull requests

1 participant