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

Tactics: case split as several declarations #582

Closed
serras opened this issue Nov 10, 2020 · 4 comments · Fixed by #1379
Closed

Tactics: case split as several declarations #582

serras opened this issue Nov 10, 2020 · 4 comments · Fixed by #1379
Labels

Comments

@serras
Copy link
Contributor

serras commented Nov 10, 2020

Right now, if I start with the following code:

go :: Maybe Int -> Int
go x = _

and use "case split on x", the result is:

go x = (case x of
   Nothing -> _
   (Just i) -> _)

which is not very idiomatic. I was wondering whether there's room for a new "case split" which would produce:

go Nothing = _
go (Just i) = _

@isovector do you have any opinions on this? I am happy to invest some time on implementing this, but I don't want to step over anybody's plans.

@isovector
Copy link
Collaborator

Hlint already has support for this; I think the play here is to just automate running hlint's suggestions over the generated span. I don't have any plans to work on this.

@expipiplus1
Copy link
Contributor

FWIW, I prefer

go x = (case x of
   Nothing -> _
   (Just i) -> _)

to

go Nothing = _
go (Just i) = _

as there isn't any repetition of go. (obviously LambdaCase is best of all!)

@georgefst
Copy link
Collaborator

georgefst commented Nov 12, 2020

HLint will suggest removing the bracket and using LambdaCase (which is what I'd personally use), but not the refactoring @serras suggested.

EDIT: Actually HLint is less keen on LambdaCase than I thought - it would only suggest it for go = \x -> case x of ....

@isovector
Copy link
Collaborator

To clarify, I'm extremely pro on this idea; I just don't have time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants