Could not find module: detect root or fail early
Motivation
In a recent stackoverflow question the asker runs into the issue that ghci
fails to load a module that seems to be in the right place.
this is my directory´s tree:
- Figures/
- Point.hs
- Circle.hs
A minimal example would be the following contents:
-- Point.hs
module Figures.Point where
-- Circle.hs
module Figures.Circle where
import Figures.Point
Now if you are in the Figures
directory and call ghci Circle.hs
, then you will get an error like:
Circle.hs:3:1: error:
Could not find module ‘Figures.Point’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Figures.Point
| ^^^^^^^^^^^^^^^^^^^^
The issue is that you should run ghci
from the parent directory as follows ghci Figures/Circle.hs
.
Proposal
I think there are two better ways to deal with this:
-
Detect that
Figures.Circle
contains theFigures
prefix and use that to automatically find the correct root directory and loadFigures.Point
without issues. -
Fail early because
Figures.Circle
does not match the name of the fileCircle.hs
.
Either of these would be an improvement to the status quo in my opinion, but I prefer option 1 if it is not too difficult.