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

Rewrite rules: specifiable imports from Prelude #193

Merged
merged 2 commits into from
Jul 23, 2023

Conversation

viktorcsimma
Copy link
Contributor

Closes #192. Adds the opportunity to define the handling of Prelude in the config file. See the documentation update for details:

By default, agda2hs handles Prelude like other modules: it collects all the identifiers it finds we use from Prelude, and adds them to Prelude's import list.

In the config YAML, we can specify a different behaviour. The format is:

# First, we specify how to handle Prelude.
prelude:
  implicit: true
  hiding:           # if implicit is true
    - seq

  #using:           # if implicit is false
  #  - +
  #  - Num

# Then the rules themselves.
rules:

  # The rational type.
  - from: Data.Rational.Unnormalised.Base.ℚᵘ
    to: Rational
    importing: Data.Ratio
  - [...]

If implicit is true, then everything gets imported from Prelude, except for those that are specified in the hiding list. This can cause clashes if you reuse names from Prelude, hence the opportunity for a hiding list. If there is no such list, then everything gets imported.

If implicit is false, Prelude gets imported explicitly, and only those identifiers that are specified in the using list. If there is no such list, agda2hs reverts to the default behaviour (it tries to collect imports by itself).

@viktorcsimma viktorcsimma changed the title Prelude options Rewrite rules: specifiable imports from Prelude Jul 21, 2023
@jespercockx
Copy link
Member

Thanks, this is great once again! I'm actually thinking that perhaps it would even be a good idea to have implicit prelude set to true, since it is less likely to cause problems with identifiers being out of scope (at the cost of potentially having name clashes, but it is probably a good thing to have an error when you accidentally introduce a name clash with a function from Prelude).

@viktorcsimma
Copy link
Contributor Author

Thank you:) I've tried out setting the default to an implicit Prelude, but this broke the tests in cases where Haskell.Prelude was imported with a qualifier (usually Pre). This might be solved by a qualified import, but then we would have to deal with the case when some of it is imported with a qualifier and some of it is not. Another option would be to simply delete the qualifier, but this would then create clashes that did not exist in the Agda code.

What do you think? Maybe we should leave it as it is for now and create an issue for changing the default.

@jespercockx
Copy link
Member

Sure, that's a good idea.

@jespercockx jespercockx merged commit fcd2885 into agda:master Jul 23, 2023
@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.

Rewrite rules' handling of Prelude (and a bug when instantiating a Haskell type class)
2 participants