Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add Comments.tmPreferences to disable indentation on comments; this screws up the compiler sometimes. #127

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants

... indented commented line in Haskell will sometimes screw up the compiler. For example:

foo :: Int -> Int -> String
foo x y
| x < y = "Less Than"
--| x == y = "Equal"
| x > y = "Greater Than"

main = do
putStrLn (foo 1 2)

This code will fail to compile with an error: "src/Main.hs:4:20: parse error on input `='"

Move the comment to the beginning of the line like so:

foo :: Int -> Int -> String
foo x y
| x < y = "Less Than"
-- | x == y = "Equal"
| x > y = "Greater Than"

main = do
putStrLn (foo 1 2)

And everything compiles just fine.

@lambdaknight lambdaknight Add Comments.tmPreferences to disable indentation on comments. Having…
… an indented commented line in Haskell will sometimes screw up the compiler. For example:

foo :: Int -> Int -> String
foo x y
    | x < y = "Less Than"
    --| x == y = "Equal"
    | x > y = "Greater Than"

main = do
    putStrLn (foo 1 2)

This code will fail to compile with an error: "src/Main.hs:4:20: parse error on input `='"

Move the comment to the beginning of the line like so:

foo :: Int -> Int -> String
foo x y
    | x < y = "Less Than"
--  | x == y = "Equal"
    | x > y = "Greater Than"

main = do
    putStrLn (foo 1 2)

And everything compiles just fine.
da4caf7
Owner

nh2 commented Dec 21, 2013

Are you sure this is necessary? If I remember correctly, it is sufficient if you change the comment string from -- to -- (with a space in front), since -- is actually the canonical Haskell comment and it's wrong in the syntax definition that comes with Sublime.

I never found out how to override just that setting.

Owner

mvoidex commented Dec 21, 2013

Does --| x == y = "Equal" causes the error or -- | x == y = "Equal" (note the space after --) causes it too?
Since --| is illegal as beginning of comment

The sequence of dashes must not form part of a legal lexeme. For example, “-->” or “|--” do not begin a comment, because both of these are legal lexemes; however “--foo” does start a comment.

http://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-170002.3

You are right. Changing line 29 of Comments.tmPreferences to "-- " (with the space after the --) also works.

Owner

mvoidex commented Dec 23, 2013

I still don't understand, why should we disable indent of comments?
Indented comment doesn't screw up compiler, invalid comment (--|) does, and there will be no error with indented comment starting with -- |

Contributor

bscottm commented Mar 29, 2017

@mvoidex: "-- |" is the start of a Haddock comment and GHC treats these comments differently than other comments. :-)

Closing.

@bscottm bscottm closed this Mar 29, 2017

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