Shortening if-then-else

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Shortening if-then-else

Arjan van IJzendoorn wrote:
 | > Is there a shorter way to write the if-then-else part
 | >        if (cmdType cmd) /= (CmdSitError Server)
 | >           then return $ Just seat_num
 | >           else return Nothing
 | return $ if cmdType cmd /= CmdSitError Serv
 | then Just seat_num else Nothing

There's a subtle change in semantics when we move the 'if'
inside the 'return'.

The original code requires the condition to be evaluated as
part of the do-expression's monad's structure, but the
translated code defers it.

'return $! if ...' would be closer to the original.

Haskell-Cafe mailing list
[hidden email]