[GHC] #11418: Suggest correct spelling when module is not found because of typo

GHC ghc-devs at haskell.org
Mon Jan 18 01:40:51 UTC 2016


#11418: Suggest correct spelling when module is not found because of typo
-------------------------------------+-------------------------------------
        Reporter:  syd               |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  lowest            |            Milestone:
       Component:  Compiler          |              Version:
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by syd):

 Replying to [comment:14 thomie]:
 > If the `.hs` file exists, GHC doesn't check for the `.lhs` file. I
 didn't make that clear.
 I assumed as much. I was just stating the worst-case.
 >
 > There is no difference between `ghc` and `ghc --make`: `--make` is the
 default mode. There is a difference between `-c` and `--make`.
 Okay. Thanks for clarrifying.
 >
 > It would help if you described how you would like this caching mechanism
 to work, and how it would help with suggesting the correct spelling when a
 module is not found. Use the example from the description, or a different
 example if that makes things more clear. Don't worry too much about how
 GHC currently works; we can get back to that afterwards.

 The caching system for module locations could work like this:

 Before compiling anything, ghc could scan the directory to find all the
 Haskell modules that are there and build a `Map ModuleName FilePath`
 (pseudocode).

 This assumes that there is not much in the directories other than the code
 you're trying to compile.
 It also assumes that you're not moving around modules during compilation.
 Both relatively valid assumptions.

 Applied to the example above:

 `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.

 Next, when going through `Aaa`, `ghc` figures out it needs to compile
 `Bbb` so it looks in the map to find the filepath where it's stored. (No
 more lookups in the filesystem at this point.)

 When `ghc` encounters `import BBb` (the spelling error) it looks in the
 map and notices that it cannot find `BBb`. It then goes through all the
 keys of the map and calculates the hamming distance/insert distance/some
 other metric between between the key and `BBb`. It notices that `Bbb` and
 `BBb` are similar and outputs the following helpful error message.

 {{{
 Aaa.hs:3:1:
     Could not find module BBb.
     Perhaps you meant Bbb instead of BBb at line 3 of module Aaa (Aaa.hs)
 }}}

 Perhaps it could even locate the spelling mistake:

 {{{
 Actual   BBb
 Expected Bbb
 Diff     _b_
 }}}

 If anything is still unclear about this idea. Please don't hesitate to
 ask.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11418#comment:15>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list