Opened 9 years ago

Closed 8 years ago

#5330 closed bug (fixed)

GHC does not follow offside rule specified as in Haskell Standard

Reported by: seba Owned by: igloo
Priority: high Milestone: 7.4.1
Component: Compiler (Parser) Version: 7.0.3
Keywords: layout, offside Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


GHC parses the following code wrongly according to the Haskell Standard (both 98 and 2010):

foo =
  do twice $ do
     putStrLn "abc"
     putStrLn "def"

GHC does:

foo =
  do {twice $ do
     {putStrLn "abc"
     ;putStrLn "def"}}

According to the Haskell Standard, the augmented input stream is:

foo =
  <3>do {6}twice $ do
        {6}putStrLn "abc"
        <6>putStrLn "def"

When considering the second '{6}' token, the stack of layout contexts consists of the single entry '6'. Therefore, only the fifth layout rule applies, which prescribes an empty block (even though empty do blocks are illegal). Layout rule in Haskell Standard

Thus, GHC should parse the above example as follows (and indicate an error regarding the empty do block):

foo =
  do {twice $ do {}
     ;putStrLn "abc"
     ;putStrLn "def"}

Change History (3)

comment:1 Changed 9 years ago by igloo

Milestone: 7.2.1
Owner: set to igloo
Priority: normalhigh

This is because GHC has NondecreasingIndentation on by default.

If you use -XNoNondecreasingIndentation, {-# LANGUAGE NoNondecreasingIndentation #-}, -XHaskell2010 or {-# LANGUAGE Haskell2010 #-} then you will get the parse that you expect.

This doesn't seem to be documented as far as I can see, so we should document it.

comment:2 Changed 8 years ago by igloo


comment:3 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed


commit 6361b7fa141ce0c0120e9e8ff31344c419c13bed
Author: Ian Lynagh <>
Date:   Wed Oct 5 00:50:42 2011 +0100

    Update the "Known bugs and infelicities" section of the manual
Note: See TracTickets for help on using tickets.