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

[Builtins] Add detection of applied type variables to the elaboration machinery #4648

Merged

Conversation

effectfully
Copy link
Contributor

This:

  1. drops some stupid hardcoded checks only working for particular type classes in the Type context
  2. adds a general check that works in both the Rep and Type contexts and gives the user a more specific error message due to being context-aware

I've tested it manually, gonna commit some example error message in a subsequent PR (I need a bit of additional machinery for that, hence a different PR).

Copy link
Contributor

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blind approving, I'm not sure I have the brain space to learn about the type errors stuff more right now 😅

@effectfully
Copy link
Contributor Author

effectfully commented May 25, 2022

You're breaking my heart Michael, I've rewritten that damn thing four times from scratch before becoming convinced it was the simplest way of handling the most general case.

@michaelpj
Copy link
Contributor

I didn't say it wasn't the simplest possible ;)

-- | Throw an error telling the user not to apply type variables to anything.
type ThrowNoAppliedVars :: (GHC.Type -> GHC.Type) -> GHC.Constraint
type family ThrowNoAppliedVars hole where
-- In the Rep context higher-kinded type variables are allowed, but need to be applied via
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a See Note [Rep vs Type context] here in case someone finds the "Rep/Type context" terminology unfamiliar.

Copy link
Contributor Author

@effectfully effectfully May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

'Text " applied via regular type application" ':$$:
'Text "To fix this error instantiate all higher-kinded type variables"

instance TypeError NoRegularlyAppliedHkVarsMsg => Functor (Opaque val) where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to remove these specific instances. I assume you can do something similar to the TypeError NoConstraintsErrMsg => Eq (Opaque val rep) instance and similar ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unfortunately. We can barf on any applied type variable, but we can't barf on any variable appearing in the argument position as it's perfectly fine to have an argument whose type is a type variable (as in IfThenElse). It's really about not allowing any constraints and for that the best we can do is hardcode some of them.

@effectfully effectfully force-pushed the effectfully/builtins/add-detection-of-higher-kinded-vars branch from a22e01d to 79f3c58 Compare May 26, 2022 18:20
@effectfully effectfully force-pushed the effectfully/builtins/add-detection-of-higher-kinded-vars branch from 79f3c58 to 177e942 Compare May 26, 2022 19:33
@effectfully effectfully enabled auto-merge (squash) May 26, 2022 20:06
@effectfully effectfully merged commit 2bdb9a5 into master May 26, 2022
@effectfully effectfully deleted the effectfully/builtins/add-detection-of-higher-kinded-vars branch May 26, 2022 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants