# Lexical syntax of comments and layout

**URL:** <https://discourse.haskell.org/t/lexical-syntax-of-comments-and-layout/12296>\
**Category:** Uncategorized\
**Created:** [June 12, 2025, 6:58pm UTC](https://discourse.haskell.org/t/lexical-syntax-of-comments-and-layout/12296 "2025-06-12T18:58:52Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![natefaubion](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/natefaubion/32/5194_2.png) [@natefaubion](https://discourse.haskell.org/u/natefaubion)\
**Post date:** [June 12, 2025, 6:58pm UTC](https://discourse.haskell.org/t/lexical-syntax-of-comments-and-layout/12296/1 "2025-06-12T18:58:52Z")

</div>

In keeping with [Wadler’s Law](https://wiki.haskell.org/Wadler's_Law), an interesting subject came up in the PureScript Discord regarding delimited/block comment syntax and layout.

GHC sees both of these definitions as valid:

```haskell
example1 =
  let
      foo = id{-
-}42
      bar = foo
  in bar
  
example2 =
  let
      foo = id 42
{- -}bar = foo
  in bar

```

This is interesting because in `example1`, the block comment causes the parser to ignore the column of 42, parsing `id 42` as the RHS of `foo`. In `example2`, there is no actual indentation, only the block comment. The parser only consults the visual column of `bar`.

In comparison, given this PureScript

```haskell
example1 =
  let
      foo = identity {-
-}42
      bar = foo
  in bar
  
example2 =
  let
      foo = identity 42
{- -}bar = foo
  in bar

```

Purs will fail on `example1` because it consults the column of every token for the purposes of layout (layout is transformation on the token stream only). It will accept `example2` for the same reason as GHC.

Both parsers are problematic though if you think comments are insignificant. If by “insignificant” we mean that we should be able to strip comments from the source and retain an identical parse, then both parsers should fail to parse `example2`. If we remove the comments from `example2`, then it will fail to parse due to incorrect indentation, making comments significant in both compilers! 😮

I would be interested in the consistency among alternative Haskell parsers that aren’t derived from GHC. This obviously doesn’t really affect anyone in practice, but an interesting artifact of naive columnar indentation nonetheless. Maybe Python was right to only have line comments!

---

_[View the full topic](https://discourse.haskell.org/t/lexical-syntax-of-comments-and-layout/12296)._
