[Haskell-cafe] Parsing error in Haskell2010

Roman Cheplyaka roma at ro-che.info
Tue Nov 18 23:23:39 UTC 2014


To quote the GHC manual:

In Haskell 98 mode and by default (but not in Haskell 2010 mode), GHC is
a little less strict about the layout rule when used in do expressions.
Specifically, the restriction that "a nested context must be indented
further to the right than the enclosing context" is relaxed to allow the
nested context to be at the same level as the enclosing context, if the
enclosing context is a do expression.

This behaviour is controlled by the NondecreasingIndentation extension.

On 18/11/14 18:45, Stuart A. Kurtz wrote:
> Dear Cafe,
> 
> I recently ran into a Haskell2010 parsing error with code that parses just fine under Haskell98, and it seems to me that this might be an unintended consequence.
> 
> Briefly, I have
> 
> 	runModel :: StdGen -> Model () -> Result
> 
> where Model is a monadic type, and then my main was
> 
> 	main :: IO ()
> 	main = do
> 	    gen <- getStdGen
>             let log = runModel gen $ do
> 	        initialize 72
> 	        report
> 	        replicateM_ 50 $ do
> 	            replicateM_251 migrate
> 	            report
> 	    putStr . format $ log
> 
> Haskell 2010 doesn't like the additional level of indentation after the "let log" line. If I pull the content of the "do" into a separate definition, so this becomes
> 
> 	    let log = runModel gen simulate
> 
> the parsing error goes away.
> 
> Questions:
> 
> 1) Is this intended?
> 2) Can this code be formatted in a way to make Haskell 2010 happy?
> 
> Many thanks.
> 
> Peace,
> 
> Stu



More information about the Haskell-Cafe mailing list