Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: Default module prefix [duplicate]

Tags:

haskell

cabal

In Haskell, modules name and file name containing the module have to be the same. The problem is is not only the file name but the includes the all path, so you have (AFAIK) to create a directory structure matching the module hierarchy, which is a bit annoying.

For example, let's say that I'm writing a datatype D in a module M which I think should be in Database. The module name should be Database.M.T. As my main directory is already called M (the name of the package) I end up with the following directory structure :

M:
|
+-- Database:
    |
    +-- M:
        |
        + A.hs

Is that possible to just do :

M:
|
+ A.hs

And export M as Database.M ?

like image 747
mb14 Avatar asked Jun 15 '14 09:06

mb14


1 Answers

This isn't possible at present, short of using symlinks or similar to point Database.M to M which would have various problems with portability and version control.

Simon Marlow proposed a new option for GHC to add support for aliases a few months ago: http://www.haskell.org/pipermail/glasgow-haskell-users/2014-April/024920.html

His idea was that you could run ghc with a new variant of the -i option:

ghc -iDatabase.M=M

and then anything in the M folder would be treated as being part of Database.M as you want.

You'd also be able to put the new option in the hs-source-dirs field in .cabal files.

However there were various objections to the proposal so he's withdrawn it for now. The main problems were that it adds complexity and several other tools (e.g. cabal) would also have to be changed to support it.

like image 193
GS - Apologise to Monica Avatar answered Nov 24 '22 18:11

GS - Apologise to Monica