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

Indentation of non-parallel list comprehensions is wrong. #14

Closed
bremner opened this issue Mar 25, 2012 · 6 comments
Closed

Indentation of non-parallel list comprehensions is wrong. #14

bremner opened this issue Mar 25, 2012 · 6 comments

Comments

@bremner
Copy link

bremner commented Mar 25, 2012

forwarding http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=343248
Daniel Burrows writes:

haskell-mode indents parallel list comprehensions (the GHC extension)
just fine, but it seems to have trouble with non-parallel ones. For
instance, consider this code fragment:

allCards :: CardUniverse -> [CardValue]
allCards (CardUniverse s free) = free ++ suited
    where suited = [cv | suit <- s,
                         (cv, _) <- elems (suitCards suit)]

haskell-mode wants me to indent the last line to either the level of
"s" or the level of "cv" in the previous line; for instance:

-- | Returns a list of all the cards in the universe; this will be a
-- set if the universe is well-formed.
allCards :: CardUniverse -> [CardValue]
allCards (CardUniverse s free) = free ++ suited
    where suited = [cv | suit <- s,
                    (cv, _) <- elems (suitCards suit)]

I verified that this behaviour still exists with 2.8.0 and turn-on-haskell-indentation

@hvr
Copy link
Member

hvr commented Mar 25, 2012

btw, if you follow the leading-comma Haskell convention for list-like structures, e.g. as in

-- | Returns a list of all the cards in the universe; this will be a
-- set if the universe is well-formed.
allCards :: CardUniverse -> [CardValue]
allCards (CardUniverse s free) = free ++ suited
  where suited = [cv | suit <- s
                     , (cv, _) <- elems (suitCards suit)
                     ]

does it work as espected?

@bremner
Copy link
Author

bremner commented Mar 25, 2012

yes, that indentation looks reasonable to me in the leading-comma case.

@pheaver
Copy link
Contributor

pheaver commented Mar 26, 2012

Ah, I have noticed this problem all the time, but just kept pushing it to the back of my mind. It would be nice to fix it.

@hvr
Copy link
Member

hvr commented Mar 28, 2012

@pheaver btw there's a related problem occurring even when using the leading-comma convention: when using let bindings within list comprehensions, at least one of the 3 indentation modes gets confused...

@chrisdone
Copy link
Member

Gonna close in one month unless someone owns this.

@lukehoersten
Copy link
Member

As Chris mentioned back in 2013, he was going to close this in a month. I confirmed hi2-mode still has this same behavior but the recommended indentation works correctly as this:

allCards :: CardUniverse -> [CardValue]
allCards (CardUniverse s free) = free ++ suited
  where suited = [ cv | suit <- s
                      , (cv, _) <- elems (suitCards suit)
                      ]

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

No branches or pull requests

6 participants