0

Haskell disallows the following style of nested guards although they look aesthetically natural and concise:

x | condition_1
    | condition_1_1
      | condition_1_1_1 = expression_1_1_1
      | ...
    | ...
  | ...

I got a few pointers e.g. 1 and 2, but still can't help ask:

Needn't we bother such negligible syntactical sugar?

Would the implementation introduce prohibitive incompatibility?

Do deep nested guards resonate too much with imperative programming to easily promote them?

Community
  • 1
  • 1
sof
  • 9,113
  • 16
  • 57
  • 83
  • I wanted this for forever. I was really disappointed to learn it wasn't possible. – Carcigenicate Oct 31 '16 at 00:06
  • 2
    Guards do not participate in layout, so your suggested syntax would be highly ambiguous. – Reid Barton Oct 31 '16 at 00:09
  • What Reid Barton suggests is, I guess, the most likely reason why no one bothered yet. In general, I don't think concerns such as "resonate too much with imperative programming" hold much water -- after all, we have `if`, `case` and `do` already. On the other hand, I believe this sort of nesting remove most of the clarity adding by the guards syntax, so we might as well just use nested `if`. – duplode Oct 31 '16 at 00:21

0 Answers0