I've found that I don't know how to handle nested if-else-then in do-blocks in Haskell.
I know already that I can use a case, but that would require all my conditions (a, b and c) to return the same type (Bool, so there are only two cases, but I need three distinct ones) and is therefore not as general (correct me if I'm wrong). I have also tried considering using guards here, but I don't know how to make this work in a do statement, especially if the -- something expressions are meant to be of type IO ().
Suppose I have the following code that is inside a do:
if a then
-- something
else
if b then
-- something
else
if c then
-- something
else
-- something
How do I create the equivalent logic but without all the indenting?
-- somethingplaceholders to return the same type, so your objection tocasedoesn't really apply.Bool. (2) "I have also tried considering using guards here, but I don't know how to make this work in a do statement" -- You can't use guards within a do-block; if-expressions are indeed the right thing to reach for.-- somethingplaceholders returning the same type that I am trying to avoid, it is the conditions (a,bandc). I've edited my answer.