Can't handle INLINE pragma on the first line of a where clause #20

Closed
opened 2017-04-09 22:37:45 +02:00 by barrucadu · 4 comments
barrucadu commented 2017-04-09 22:37:45 +02:00 (Migrated from github.com)

This works fine:

answer :: Int
answer = x where
  x = 42
  {-# INLINE x #-}

This causes brittany to die with "ERROR: brittany pretty printer returned syntactically invalid result."

answer :: Int
answer = x where
  {-# INLINE x #-}
  x = 42
This works fine: ```haskell answer :: Int answer = x where x = 42 {-# INLINE x #-} ``` This causes brittany to die with "ERROR: brittany pretty printer returned syntactically invalid result." ```haskell answer :: Int answer = x where {-# INLINE x #-} x = 42 ```
lspitzner commented 2017-04-09 23:55:56 +02:00 (Migrated from github.com)

it boils down to this being a syntax error:

foo = r
 where
   {-# INLINE r #-}
  r = undefined

which I did not anticipate. Pragmas don't count as comments and affect the layouting-rule? Pragmas count as comments but still affect the layouting-rule? I'll have to consult the report for this,,

(The fact that the pragma is placed there in the output might be a minor error nonetheless, I'll have to look into this. Perhaps I can tweak the where-clause-layouting to get rid of this.)

it boils down to this being a syntax error: ~~~~.hs foo = r where {-# INLINE r #-} r = undefined ~~~~ which I did not anticipate. Pragmas don't count as comments and affect the layouting-rule? Pragmas count as comments but still affect the layouting-rule? I'll have to consult the report for this,, (The fact that the pragma is placed there in the output might be a minor error nonetheless, I'll have to look into this. Perhaps I can tweak the where-clause-layouting to get rid of this.)
lspitzner commented 2017-04-09 23:58:42 +02:00 (Migrated from github.com)

Some compiler implementations support compiler pragmas, which are used to give additional instructions or hints to the compiler, but which do not form part of the Haskell language proper and do not change a program’s semantics

(2010 report)

Well.. syntax error vs no syntax error does count as a change in semantics, doesn't it, heh.

> Some compiler implementations support compiler pragmas, which are used to give additional instructions or hints to the compiler, but which do not form part of the Haskell language proper and do not change a program’s semantics ([2010 report](https://www.haskell.org/onlinereport/haskell2010/haskellch12.html#x19-18800012)) Well.. syntax error vs no syntax error does count as a change in semantics, doesn't it, heh.
ElvishJerricco commented 2017-04-10 00:00:54 +02:00 (Migrated from github.com)

Then it certainly seems like a bug in GHC that this is a syntax error;
should probably just be a warning like "Warning: incorrect indentation
invalidating INLINE pragma."
On Sun, Apr 9, 2017 at 5:58 PM Lennart Spitzner notifications@github.com
wrote:

Some compiler implementations support compiler pragmas, which are used to
give additional instructions or hints to the compiler, but which do not
form part of the Haskell language proper and do not change a program’s
semantics

(2010 report
https://www.haskell.org/onlinereport/haskell2010/haskellch12.html#x19-18800012
)

Well.. syntax error vs no syntax error does count as a change in
semantics, doesn't it, heh.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/lspitzner/brittany/issues/20#issuecomment-292816565,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABTWvLdGBzfCPpJqNjLiSD5uS9J1YA7Xks5ruVSSgaJpZM4M4JRD
.

Then it certainly seems like a bug in GHC that this is a syntax error; should probably just be a warning like "Warning: incorrect indentation invalidating INLINE pragma." On Sun, Apr 9, 2017 at 5:58 PM Lennart Spitzner <notifications@github.com> wrote: > Some compiler implementations support compiler pragmas, which are used to > give additional instructions or hints to the compiler, but which do not > form part of the Haskell language proper and do not change a program’s > semantics > > (2010 report > <https://www.haskell.org/onlinereport/haskell2010/haskellch12.html#x19-18800012> > ) > > Well.. syntax error vs no syntax error does count as a change in > semantics, doesn't it, heh. > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/lspitzner/brittany/issues/20#issuecomment-292816565>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/ABTWvLdGBzfCPpJqNjLiSD5uS9J1YA7Xks5ruVSSgaJpZM4M4JRD> > . >
lspitzner commented 2017-04-12 22:07:24 +02:00 (Migrated from github.com)

for those curious, my current understanding regarding pragmas: they are like optional keywords. the compiler is free to interpret them either as comments (ignore them, effectively) or consider them like keywords including corresponding lexical/syntactical "powers". giving them a lexical look similar to comments has two advantages: 1) compiler implementors are free to ignore that part and have them treated as comments 2) adding new pragmas is much less of an issue than adding new keywords to the language.

this is not very clear in the 2010 report, but with this understanding the above error itself (from ghc) is valid.

for those curious, my current understanding regarding pragmas: they are like optional keywords. the compiler is free to interpret them either as comments (ignore them, effectively) or consider them like keywords including corresponding lexical/syntactical "powers". giving them a lexical look similar to comments has two advantages: 1) compiler implementors are free to ignore that part and have them treated as comments 2) adding new pragmas is much less of an issue than adding new keywords to the language. this is not very clear in the 2010 report, but with this understanding the above error itself (from ghc) is valid.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#20
There is no content yet.