[Haskell-cafe] Shortening if-then-else

Matthias Neubauer neubauer at informatik.uni-freiburg.de
Tue Nov 22 13:17:57 EST 2005


Arjan van IJzendoorn <afie at cs.uu.nl> writes:

>> 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

return $ guard (cmdType cmd /= CmdSitError Serv) >> return seat_num

-Matthias

-- 
Matthias Neubauer                                       |
Universität Freiburg, Institut für Informatik           | tel +49 761 203 8060
Georges-Köhler-Allee 79, 79110 Freiburg i. Br., Germany | fax +49 761 203 8052


More information about the Haskell-Cafe mailing list