私はそのようなことをするための正しくエレガントな方法を考えていました
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
何にも一致しない while を使用することは、正しい方法ではないようです。