[Haskell-cafe] Parsing error in Haskell2010

Matteo Ferrando matteo.ferrando2 at gmail.com
Wed Nov 19 17:38:51 UTC 2014


Stuart,

As Roman says, GHC is expecting that everything in that indentation level
will be a new binding, that's te reason of giving the error *on the next
line*, is because it was still *looking* for a `=` when it found `report`.

As of why Haskell2010 changed this behaviour, I have no idea, but I'm sure
the people behind this had good reasons (I find Haskell2010's behaviour
more desirable).

You can always use the `NondecreasingIndentation` suggested by Roman.

Cheers,

Matteo

On Wed, Nov 19, 2014 at 9:26 AM, Roman Cheplyaka <roma at ro-che.info> wrote:

> The first lexeme after let is log. Everything indented same as log (that
> is, starting at the same column as log) is considered to be bindings
> inside that let; everything indented more is considered to be
> continuation of a binding.
>
> In your original example, initialize is indented same as log, so ghc
> tries to parse it as a binding, and fails.
>
> The NondecreasingIndentation that I mentioned in the other email relaxes
> this constraint.
>
> On 19/11/14 14:45, Stuart A. Kurtz wrote:
> > Dear Matteo,
> >
> > The surprise for me comes from the idea that the *amount* of indentation
> matters on establishing a new block, which hasn't been my experience with
> Haskell's offside rule before, although I tend to be 4-ist when it comes to
> indenting, and it's possible that this behavior has kept me on the good
> side thus far of rules that I wasn't aware of.
> >
> > So my instinct would have been to indent the code the way you've done
> below, but only if there were additional let bindings. It is particularly
> confusing that the error is reported as being on the "report" line, which
> seems to imply that the indentation of the previous line was ok (and
> therefore that the implicit block of which it is a part had been set up
> based on the do). It's nothing new to see syntax errors reported a line
> late -- the Pascal compilers did that! -- but unexpected here because GHC
> seems quite good about locating errors.
> >
> > Peace,
> >
> > Stu
> >
> >
> >> On Nov 18, 2014, at 11:16 PM, Matteo Ferrando <
> matteo.ferrando2 at gmail.com> wrote:
> >>
> >>> This seems to be the issue. Haskell98 didn't require this, Haskell2010
> does, and this seems less desirable to me. Isn't it reasonable to assume
> that the it's the do that dominates syntactically here, and not the let?
> >>
> >> No, so you can do stuff like:
> >>
> >>     main = do
> >>         gen <- getStdGen
> >>         let log = runModel gen $ do
> >>                 initialize 72
> >>                 report
> >>                 replicateM_ 50 $ do
> >>                     replicateM_251 migrate
> >>                     report
> >>             log' = runModel gen $ do
> >>                 initialize 42
> >>                 report
> >>                 replicateM_ 50 $ do
> >>                     replicateM_251 migrate
> >>                     report
> >>             log'' = runModel gen $ do
> >>                 initialize 42
> >>                 report
> >>                 replicateM_ 50 $ do
> >>                     replicateM_251 migrate
> >>                     report
> >>         putStr . format $ log
> >>         putStr . format $ log'
> >>         putStr . format $ log''
> >>
> >> Defining `log`, `log'` and `log''` with the same `let`.
> >>
> >> Cheers,
> >>
> >> Matteo
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141119/7e137c63/attachment.html>


More information about the Haskell-Cafe mailing list