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

Suggestions or actions to use type synonyms #506

Open
expipiplus1 opened this issue Oct 16, 2020 · 5 comments
Open

Suggestions or actions to use type synonyms #506

expipiplus1 opened this issue Oct 16, 2020 · 5 comments
Labels
type: enhancement New feature or request

Comments

@expipiplus1
Copy link
Contributor

It would perhaps be nice if HLS suggested using in scope type synonyms sometimes.

To make an example using the hnix package: if I use the excellent code action Define funArity :: Fix (Compose (Ann SrcSpan) NExprF) -> Int I end up with the unhuman given type sig, when funArity :: NExprLoc -> Int would be much nicer.

It's probably quite hard to come up with the perfect rule here, but how do people feel about a heuristic along the lines of:

  • The sig is in scope
  • The types are equal
  • Using the synonym is much shorter

(Better but more difficult would be to calculate the preference in existing code (user and library) between the synonym and the expanded version)

@jneira jneira added the type: enhancement New feature or request label Oct 16, 2020
@mpardalos
Copy link
Contributor

mpardalos commented Mar 3, 2021

Is there still interest in this feature? I would be interested in working on it.

@expipiplus1
Copy link
Contributor Author

expipiplus1 commented Mar 4, 2021 via email

@sullyj3
Copy link

sullyj3 commented Apr 19, 2021

This seems maybe like something that ought to be in hlint?

@ndmitchell
Copy link
Collaborator

This can't really be in HLint, since sometimes type synonyms have semantic information that HLint just can't know. For example, FilePath vs String is an important distinction. Having the ability to do type-level suggestions makes sense, and I think that might be a useful feature to add to HLint, but it can't just infer that a synonym should be used instead, the user would have to opt in with configuration.

@jneira
Copy link
Member

jneira commented Sep 21, 2021

It would be great to have code actions in both directions:

  • use the type synonym when appropiate
  • but convert a use of the type sysnonym in its original type signature, recursively. It could help to understand it better in the call site (and return to use it auto after that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants