Changes between Version 6 and Version 7 of Proposal/HelpfulImportError


Ignore:
Timestamp:
Feb 17, 2016 10:27:14 AM (4 years ago)
Author:
syd
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Proposal/HelpfulImportError

    v6 v7  
    5151* Since neither file exists, an error message is shown [...]
    5252
    53 Let n be the number of files that are recursively referenced and m the number of source directories specified, GHC looks for 2*m*n files.
    54 The 2 comes from the `.hs`/`.lhs` options.
     53=== Proposed solution (thomie)
    5554
    56 == First Proposed solution ==
     55Cabal already asks you to specify all known modules in either `exposed-modules` or `other-modules`.
     56Cabal already passes this list of modules to GHC.
     57GHC therefore already knows the names of all modules that could possibly be imported (not quite, see ​https://github.com/haskell/cabal/issues/2982#issuecomment-169786310)
     58This list could be used to detect import typo's.
     59
     60Applied to the example above:
     61
     62`ghc --make Aaa.hs` first looks through the directory and finds `Aaa` in file `Aaa.hs` and `Bbb` in file `Bbb.hs`. It then gives this information to any subsequent compilation procedures.
     63
     64When `ghc` encounters `import BBb` (the spelling error) it looks in the list and the directory and notices that it cannot find `BBb`.
     65This is where `ghc` throws a compile error saying it cannot find the module.
     66Instead, `ghc` could now also look through the list for potential spelling mistakes.
     67Because `Bbb` is in the list of available modules, it notices that `Bbb` is there and is similar to `BBb`.
     68It then outputs the following helpful error message.
     69
     70{{{
     71Aaa.hs:3:1:
     72    Could not find module BBb.
     73    Perhaps you meant Bbb instead of BBb at line 3 of module Aaa (Aaa.hs)
     74}}}
     75
     76Perhaps it could even locate the spelling mistake:
     77
     78{{{
     79Actual   BBb
     80Expected Bbb
     81Diff     _b_
     82}}}
     83
     84This feature could be called {{{-fhelpful-import-errors}}} and should be turned on by default.
     85
     86== Old Proposed solution (No longer relevant but maybe historically useful) ==
    5787
    5888Before compiling anything, ghc could scan the directory to find all the Haskell modules that are there and build a `Map ModuleName FilePath` (pseudocode).
     
    128158Cons:
    129159- Negates the advantage of making the compiler purer.
    130 
    131 === Second proposed solution (thomie)
    132 
    133 * A lot of people use Cabal for library development
    134 * Cabal already asks you to specify all known modules in either exposed-modules or other-modules (I guess you could make typos here..)
    135 * Cabal already passes this list of modules to GHC
    136 * So GHC already knows the names of all modules that could possibly be imported (not quite, see ​https://github.com/haskell/cabal/issues/2982#issuecomment-169786310)
    137 * Use that list of modules to make spelling suggestions on import errors