Conditional logic chooses between two expressions using a Boolean condition. In Haskell, if-then-else is an expression, so both branches are required and must produce a usable value. section 2.4.3
Use conditional expressions when a function or action must choose between alternatives:
- Write `if condition then expression1 else expression2`; an if without else is invalid because it might not evaluate to a value. section 2.4.3
- Keep both branches compatible. In an IO action, both branches must evaluate to actions of the same type, such as `IO ()`. section 3.1.3 section 3.5
- Replace deeply nested conditionals with guards when several Boolean cases make the function difficult to read. section 2.4.3
Choosing a character transformation
A character rotation function can preserve nonletters while selecting different helpers for lowercase and uppercase input: `rotChar n ch = if isLower ch then lowerRot n ch else if isUpper ch then upperRot n ch else ch`. For example, rotating `'A'` by 13 produces `'N'`, while rotating `'1'` preserves `'1'`. section 2.4.3
ghci> x = 10 :: Int ghci> if x > 5 then "x is larger than 5" else "x is not larger than 5" "x is larger than 5"
Evaluate a conditional directly in GHCi and observe that the selected branch produces a string value. section 2.4.3




















