[Haskell-cafe] Parsing error in Haskell2010

Roman Cheplyaka roma at ro-che.info
Wed Nov 19 13:56:04 UTC 2014


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
> 



More information about the Haskell-Cafe mailing list