我想知道做这件事的正确和优雅的方式
function candy = case (color candy) of
Blue -> if (isTasty candy) then eat candy
else if (isSmelly candy) then dump candy
else leave candy
我试过
function candy = case (color candy) of
Blue -> dealWith candy
where dealWith c
| isTasty c = eat candy
| isSmelly c = dump candy
| otherwise = leave candy
任何人都知道如何改进这一点?
更多的
我知道我可以用这个
function candy = case (color candy) of
Blue -> case () of
_ | isTasty candy -> eat candy
| isSmelly candy -> dump candy
| otherwise -> leave candy
但是使用一段case
时间不匹配任何东西似乎不是正确的方法。