2026-08-20
Sign.hs
sign :: Int -> String
sign n
| n > 0 = "positive"
| n < 0 = "negative"
This crashes at runtime for one particular input. Which one, and how do you fix it?
Answer
sign 0 crashes with a non-exhaustive guards error — neither guard matches when n is 0. Add a catch-all: | otherwise = "zero".