[Haskell-cafe] Shortening if-then-else

Henning Thielemann lemming at henning-thielemann.de
Tue Nov 22 13:40:08 EST 2005


On Tue, 22 Nov 2005, Matthias Neubauer wrote:

> 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

Because I often need it, I'm used to use my private function 'toMaybe'

return $ toMaybe (cmdType cmd /= CmdSitError Serv) seat_num


More information about the Haskell-Cafe mailing list