Nearly every beginner error in Haskell comes from a short list: a mismatched type, a missing case, an IO value used as if it were a plain one, or indentation that does not say what you meant. The error messages are long but they are consistent, and once you know the four families you can usually fix a problem in under a minute.
Read the error from the top down
The first sentence tells you the category, and the “expected” and “actual” types tell you the mismatch. Skip the middle section on your first pass; it usually explains context you already know. Look for the line number, then look a line or two above it.
If the message mentions an expression you did not write, the problem is in the enclosing definition. That happens constantly with do blocks and long pipelines.
Mistake one: mixing a value with an action
putStrLn has type String -> IO (). Writing let x = putStrLn "hi" gives you an action, not the effect, and the next line will complain that it wanted IO () but found something else.
- Inside
do, an action on its own line runs it. - Use
<-only when you want the result of an action. - Never use
letto run something; use it to name a value.
Mistake two: forgetting a pattern
Pattern-match warnings are your friends. If you match on Just and Nothing, or on the empty list and a cons cell, the compiler can tell you when a case is missing. Treat every such warning as a bug rather than noise, and add the missing equation before running anything.
Mistake three: layout and indentation
Haskell uses indentation as syntax. A line that looks aligned in your editor may not be aligned in bytes if you mixed tabs and spaces. Turn on visible whitespace, use spaces only, and keep each do block’s statements at exactly the same column.
When an error points at a line that looks perfectly fine, check the line above it. Layout errors are almost always reported one line late.
Mistake four: type signatures that lie
If your signature says Int but the function works on any number, the compiler will force you to specialize, and later code will not compose. Write the most general signature you can, let the compiler infer one first if unsure, and use the inferred type as a guide.
Make one change, reload, and read only the first error. Commenting out code is fine, but leaving three broken edits in place turns one clear message into four confusing ones. Small steps beat clever debugging.
Most messages are telling you the same few truths: the types do not line up, a case is missing, or the layout is wrong. Learn those four shapes and the compiler stops sounding angry.