These are all good answers but the "dangling do" I think will help me the most.
–
OwenAug 10 '11 at 10:27

Because, while beautiful, the second code fragment doesn't answer the Owen's question: how to flatten several nested ifs. Also, wow, I would have guessed that to be a syntactic error. @Owen, I suppose it's a matter of preference, but I think the first fragment hides the structure of the computation: you can't immediately tell how the condition affects the rest of the code. If you can't use a short-circuiting monad (I usually write a monad instance for Either which stops on the first Left), the large if is probably a better idea.
–
scvalexAug 10 '11 at 12:07

@scvalex It's an exception in GHC's parser. IIRC, it will only work with do and possibly proc.
–
FUZxxlAug 10 '11 at 15:35

1

@FUZxxl: In section 2.7 of the Haskell report, the layout rules are defined such that the non-brace lexeme immediately following a where, let, do or of determines the indentation level. So this not GHC-specific, but part of the standard, even Haskell 98.
–
hammarAug 10 '11 at 21:19

The best way to do this is using guards, but then you need to have the y value first in order to use it in the guard. That needs to be gotten from getForX wich might be tucked away into some monad that you cannot get the value out from except through getForX (for example the IO monad) and then you have to lift the pure function that uses guards into that monad. One way of doing this is by using liftM.