Out of scope errors appear after type errors caused by them
Example:
import Control.Lens (_Just, (&))
main = Just 5 & _Just .~ 100 & print
- ~ is out of scope, the error output:
ghc-error.hs:2:17-21: error: …
• Couldn't match type ‘Maybe’ with ‘p0 a0’
Expected type: Maybe (f0 b0) -> p0 (Maybe a0) (f0 (Maybe b0))
Actual type: p0 a0 (f0 b0) -> p0 (Maybe a0) (f0 (Maybe b0))
• In the second argument of ‘(&)’, namely ‘_Just’
In the first argument of ‘(.~)’, namely ‘Just 5 & _Just’
In the expression: (.~) Just 5 & _Just 100 & print
ghc-error.hs:2:23-24: error: …
• Variable not in scope:
(.~) :: p0 (Maybe a0) (f0 (Maybe b0)) -> IO () -> t
• Perhaps you meant ‘.’ (imported from Prelude)
Perhaps you want to add ‘.~’ to the import list in the import of
‘Control.Lens’ (/home/eyal/devel/test/ghc-error.hs:1:1-32).
Compilation failed.
In larger examples, the out of scope error can be buried deep down.
In the case of operators - the fixity is unknown so it can even cause the parse to go wrong - and very weird type errors to result from that.
Out of scope errors should be put BEFORE any type errors that might be caused by them.