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

Equality alignment with guards #527

Open
marcosh opened this issue Nov 22, 2018 · 4 comments
Open

Equality alignment with guards #527

marcosh opened this issue Nov 22, 2018 · 4 comments

Comments

@marcosh
Copy link

marcosh commented Nov 22, 2018

Question

If I have a function with a guard like

f :: [Int] -> Int
f (x : xs) | x' > 5 = 37
f _ = 13

I would expect hindent to align the = signs, as in

f :: [Int] -> Int
f (x : xs) | x' > 5 = 37
f _                 = 13

Instead it aligns the = of the second line with the | of the first, as in

f :: [Int] -> Int
f (x : xs) | x' > 5 = 37
f _        = 13

Is this the desired and correct behaviour?

@toku-sa-n
Copy link
Collaborator

toku-sa-n commented Jan 16, 2023

Actually, stylish-haskell does this kind of job, although it doesn't format your input well as you're using a guard. It formats the following input

f :: [Int] -> Int
f (x : xs) = 37
f _ = 13

to

f :: [Int] -> Int
f (x : xs) = 37
f _        = 13

Btw, my recommendation is to run cat source.hs|hindent|stylish-haskell. It formats the input pretty nicely.

@mihaimaruseac Do we close this issue as it's stylish-haskell's job, or keep it open as a feature request?

@mihaimaruseac
Copy link
Owner

I think it should either not align at all (minimize git diffs) or align equals to equals

@toku-sa-n
Copy link
Collaborator

Agreed. After reviewing other issues, I've decided to keep this one open as there is another align-related issue (#230). It may be good to let HIndent consider alignments in the future.

@toku-sa-n
Copy link
Collaborator

Maybe we can implement this by using format defined in stylish-haskell.

@toku-sa-n toku-sa-n assigned toku-sa-n and unassigned toku-sa-n Apr 24, 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

No branches or pull requests

3 participants