Q:

module name and Path in haskell

I have
root/Main.hs :
import ADT.Stack

main :: IO ()
main = 
   putStrLn "Hi"

root/ADT/Stack.hs
module Stack (Stack, empty, isEmpty, push, top, pop) where
...

Upon loading Main.hs, I have the error 
File name does not match module name: …
    Saw: ‘Stack’
    Expected: ‘ADT.Stack’

If I change the module name to ADT.Stack in Stack.hs, I can get rid of the error. 
However, I dont understand the reason behind such constraint.
Is there no way to avoid specifying in the code of Stack.hs what is already encoded in the name of the directory in which it is contained ?
If there are no alternative way, is there any good reason this  ?

A:

If you're using the hierarchical namespaces, your module names should reflect the full path. So, in root/ADT/Stack.hs, you should have
module ADT.Stack (Stack, empty, isEmpty, push, top, pop) where

After that, as you have observed, everything should be fine.
I am not aware of any possibility to derive the module name not only from the name you give it in the file, but also on the location of the file. (That is what you are after, aren't you?) Of course, this should be possible with some fancy preprocessing, but you probably don't want to go there.
So, then, why are things like they are? Not sure whether, for you, it qualifies as a good reason, but one can argue that this scheme has as an advantage that by simply moving a file to another directory you don't silently break any client codes. Instead, you get an error already when compiling the moved file.
The redundancy in the file location and the module name allows processors to find imported modules with only a minimal set of "search paths". Also, it provides a standard for organising source files over larger projects.

