Hi,<br><br>I'm writing my first real Haskell program and I came up with the following code snippet.<br><br>---<br>let x' = x \+ dist \* dir<br> nx' = normal geometry<br> wi = (-1) \* dir <br> in do <br>
(p, wo) <- brdfCosSampling reflector nx' wi <br> let color' = p \** color<br> q = min 1 (scalarContribution p)<br> in do<br> sampler <- biasedCoinSampler q <br>
(radianceSampler surfaces x' wo (q \* color'))<br> (terminalRadianceSampler surfaces x' nx' ((1-q) \* color'))<br> sampler <br>---<br><br>This works just fine but I don't like the way I had to indent the code because of alternating lets and dos. <br>
I would like to indent the code more like an imperative code i.e. like this<br><br>---<br>let { <br> x' = x \+ dist \* dir ;<br> nx' = normal geometry ;<br> wi = (-1) \* dir ;<br>} in do {<br> (p, wo) <- brdfCosSampling reflector nx' wi ;<br>
let { <br> color' = p \** color ;<br> q = min 1 (scalarContribution p) ;<br>} in do {<br> sampler <- biasedCoinSampler q <br> (radianceSampler surfaces x' wo (q \* color'))<br> (terminalRadianceSampler surfaces x' nx' ((1-q) \* color')) ;<br>
sampler ;<br>}}<br>---<br><br>but without braces and semicolons. Following works also, but is ugly (and probably less efficient?).<br><br>---<br>do<br> x' <- return $ x \+ dist \* dir <br> nx' <- return $ normal geometry <br>
wi <- return $ (-1) \* dir <br> (p, wo) <- brdfCosSampling reflector nx' wi <br> color' <- return $ p \** color <br> q <- return $ min 1 (scalarContribution p) <br> sampler <- biasedCoinSampler q <br>
(radianceSampler surfaces x' wo (q \* color'))<br> (terminalRadianceSampler surfaces x' nx' ((1-q) \* color')) <br> sampler <br>---<br><br>Is there some nice trick to do this?<br>