Language.Haskell.Parser and layout rules

The function Language.Haskell.Parser.parseModule behaves somehow strange and disagrees with ghc-6.* about the set of accepted inputs. An example: -- file T1.hs: main = do args <- getArgs if null args then return [] else do ps <- mapM process args mapM print ps -- file T2.h2 main = do args <- getArgs if null args then return [] else do ps <- mapM process args mapM print ps Note the difference is an additional whitespace in T2. I think both codes are perfectly valid, but parseModule fails on T1. Is anyone able to explain why? Thanks, Mirko Rahn ---- mirak@loop:~> ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.4.20050211, for Haskell 98

On Thu, Feb 17, 2005 at 01:40:31PM +0100, Mirko Rahn wrote:
The function Language.Haskell.Parser.parseModule behaves somehow strange and disagrees with ghc-6.* about the set of accepted inputs. An example:
-- file T1.hs: main = do args <- getArgs if null args then return [] else do ps <- mapM process args mapM print ps
The Report (section 9.3, especially notes 1 and 2) says "A nested context must be further indented than the enclosing context", so this is illegal. GHC and Hugs have innovated here, but only where the inner context is a do expression; they don't accept f xs = case xs of y:ys -> case ys of z:zs -> zs

Ross Paterson
The Report (section 9.3, especially notes 1 and 2) says "A nested context must be further indented than the enclosing context", so this is illegal. GHC and Hugs have innovated here, ...
I see you are using "innovated" here in the Microsoft sense, meaning "undocumented and incompatible departure from standards". :-) Regards, Malcolm

On Thu, Feb 17, 2005 at 02:17:42PM +0000, Malcolm Wallace wrote:
Ross Paterson
writes: The Report (section 9.3, especially notes 1 and 2) says "A nested context must be further indented than the enclosing context", so this is illegal. GHC and Hugs have innovated here, ...
I see you are using "innovated" here in the Microsoft sense, meaning "undocumented and incompatible departure from standards". :-)
I think of this as a very useful feature. it should be documented in the extensions section. mainly, I find it very useful in two circumstances: short circuit return: main = do foo if bar then return baz else do whizz bang with declarations main = do withCString x $ \x' -> do withCString y $ \y' -> do c_func x' y' John -- John Meacham - ⑆repetae.net⑆john⑈

Hmm. I find both examples significantly more difficult to read for
lack of standard indentation (the first more so than the second). I'd
prefer my compiler to disallow such.
mike
John Meacham
I think of this as a very useful feature. it should be documented in the extensions section. mainly, I find it very useful in two circumstances:
short circuit return:
main = do foo if bar then return baz else do whizz bang
with declarations
main = do withCString x $ \x' -> do withCString y $ \y' -> do c_func x' y'
John

The Report (section 9.3, especially notes 1 and 2) says "A nested context must be further indented than the enclosing context", ...
Okay, I understand, but the behavoir of hugs vs ghc vs Language.Haskell.Parser is still strange: The sniplets ** A: g xs = do ys <- workM xs if null ys then return [] else do zs <- workM ys return zs ** B: g xs = do ys <- workM xs if null ys then return [] else do zs <- workM ys return zs ** C: f xs = case xs of y:ys -> case ys of z:zs -> zs ** D: f x = case x of False -> do { return x; } are accepted by A B C D ghc yes no no yes hugs yes no no no Language.Haskell.Parser.parseModule no yes yes no report no no no no It seems to me that the layout rule is incorrect implemented everywhere... regards, -- -- Mirko Rahn -- Tel +49-721 608 7504 -- --- http://liinwww.ira.uka.de/~rahn/ ---
participants (5)
-
John Meacham
-
Malcolm Wallace
-
Mike Gunter
-
Mirko Rahn
-
Ross Paterson