
Aha! GHCi (and ghc --make) has a pre-pass that looks through the file for import declarations so it can build the dependency tree, and it does this without using a proper Haskell parser. I'll bet it's ignoring the CPP directives. Probably it should flag an error, I'll look into it.
Using an improper parser sounds a little delicate. Come the time you want to make this more robust, the way Hugs does this is with some semantic actions in the parser. grepping for 'chase' in hugs98/src/parser.y gives these lines in the moduleBody production: modBody : topDecls {$$ = $1;} | impDecls chase {$$ = gc2(NIL);} | impDecls ';' chase topDecls {$$ = gc4($4);} And this rule for chasing. chase : /* empty */ {if (chase(imps)) { clearStack(); onto(imps); done(); closeAnyInput(); return 0; } $$ = gc0(NIL); } ; The C function 'chase' returns True if there are dependencies on modules we haven't loaded yet. The body of the if causes Hugs to record the offending import list and abandon compiling the current module. -- Alastair Reid reid@cs.utah.edu http://www.cs.utah.edu/~reid/