| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Could you please add some passing and failing tests where a top-level declaration does not have a type signature but there is a local type synonym used in its definition? I feel like it would be good to test that, e.g., the inferred type for the top level declaration does not mention the local synonym in such cases. |
Sorry, something went wrong.
|
(although you might want to wait until we've made a decision on whether to move forward with this, sorry) |
Sorry, something went wrong.
This implements `type X = Y` synonyms as another form of let binding, valid inside `let` expressions, `where` clauses, and `do` notation. These synonyms are hoisted to the top level during desugaring.
|
I added tests as requested (see failing/LocalTypeSynonyms5 and 6, and the end of passing/LocalTypeSynonyms); not sure they cover everything you had in mind though. Mind taking a look? (The build is failing for the same reason master is; I don't see any new hlint complaints in this PR.) |
Sorry, something went wrong.
|
Yeah, that's what I was imagining. Thanks! Also could I request that you not force-push, since it makes it a bit harder to review? We can save commit rewriting for when we're ready to merge. |
Sorry, something went wrong.
|
Oh, of course! Sorry for the trouble. |
Sorry, something went wrong.
|
No worries! 🙂 |
Sorry, something went wrong.
|
Do we need to support standalone kind signatures for polykinds? |
Sorry, something went wrong.
|
Probably! I can easily add some tests that copy what the type synonym parts of the StandaloneTypeSignatures tests do, only in an inner scope; but I think there are probably more interesting things to test around using and/or shadowing kinds from the outer scope. I'm not very comfortable with polykinds yet; do you have any particularly tricky things to exercise in mind? |
Sorry, something went wrong.
|
The primary issues I'm thinking about are:
These issues are part of what make me hesitant to implement this as a desugaring step. |
Sorry, something went wrong.
|
I could be missing something here, but is generalization a concern for type synonyms? Since there can't be cycles in type synonyms, eventually all type synonym expansions will bottom out in some type made of top level data, from which kinds can be inferred. Any parameters to type synonyms that aren't included in this final expansion are not only generalizable, they're completely irrelevant, right? There's no point in having them at all: type synonyms can't be partially applied, and everything else in the language that uses types such as instance resolution depends on the expansion, not the synonym form. So generalizing makes no difference; unused type synonym parameters at any scope, top-level or not, could be errors and I don't think any real programs would be affected. Is that right? |
Sorry, something went wrong.
|
I should clarify, I don't think there's necessarily an implementation problem with generalizing, it's more about expectations around where and how we generalize in PureScript, and if we want a consistent rule-set for generalization, and how warnings and such around it are exposed to the user. |
Sorry, something went wrong.
|
An example to test for right now would be defining a local type LocalApp a = f a synonym where f is bound in the current scope. How does the compiler treat that and warn? |
Sorry, something went wrong.
Ah, thank you, I think I see the problem now. We're talking about generalization of the type parameters that get added from the local scope. Prior to polykinds, these all had definite kinds at the forall site, either explicitly stated or implicitly Type. But now they can generalize, and the compiler warns about that, and is that right? On reflection, this seems like a specification question rather than a question about this particular implementation (although, even in the absence of a right thing, this implementation is clearly doing a wrong thing by issuing a warning about type local$1$1$LocalApp). I propose moving this conversation over to #3708. |
Sorry, something went wrong.
|
I'm closing this in favor of #3897, as I'm now reasonably convinced that getting kind signatures and the desired generalization behavior right with desugaring is more trouble than not. There are very probably still issues to work out with #3897 but for now it certainly looks like the more practical path forward (assuming of course that the maintainers ultimately decide the feature is desirable at all). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This implements type X = Y synonyms as another form of let binding,
valid inside let expressions, where clauses, and do notation.
These synonyms are hoisted to the top level during desugaring.
This is a complete attempt at #3708, but subject to change if there's feedback on that feature request. Feedback on this specific implementation is welcome here; feedback on the concept of local type synonyms should probably go there.
The biggest sin I have to confess here is using the hoisted type synonym name mangling to store data, as opposed to just being a unique string. The excuses I offer are that the data are only retrieved by reporting code in Language.PureScript.Errors and Language.PureScript.Pretty, not anywhere ‘important’, and there only through functions defined alongside the name mangling code so that the ‘magic string’ logic stays local; and that the alternative would involve changing ProperName, changing TypeSynonymDeclaration, or adding a new constructor alongside TypeSynonymDeclaration, any of which would likely require refactoring code in a much wider scope than this PR currently targets—an outcome worth avoiding not only because I'm lazy, but also because I figured you would prefer it if I kept my grubby noob hands out of the typechecker. 😄 As always, I'm happy to do the work if I'm wrong.
Closes #3708.