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

tpledger
Arjan van IJzendoorn wrote:
 | > Is there a shorter way to write the if-then-else part
below?
 | >        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.

Regards,
Tom
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe