export haskell module with different hierarchy

一世执手 提交于 2019-12-02 01:26:09

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/24228157/export-haskell-module-with-different-hierarchy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!