导出具有不同层次结构的haskell模块 [英] export haskell module with different hierarchy

查看:87
本文介绍了导出具有不同层次结构的haskell模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Haskell中,包含模块的模块名称和文件名必须相同。
问题是,不仅是文件名,而且包含了所有路径,所以你有(AFAIK)创建一个与模块层次匹配的目录结构,这有点烦人。



例如,假设我正在模块M中写入数据类型D,我认为它应该位于 Database 中。
模块名称应该是 Database.M.T 。因为我的主目录已经被称为M(包名),所以我得到了以下目录结构:

$ $ $ $ $ $ $
|
+ - 数据库:
|
+ - M:
|
+ A.hs

是否可以这样做:

  M:
|
+ A.hs

并导出 M as Database.M

解决方案

可能在目前,使用符号链接或类似的点 Database.M M ,这会在可移植性方面带来各种问题和版本控制。



Simon Marlow在几个月前提出了一个GHC的新选项来添加对别名的支持: http://www.haskell.org/pipermail/glasgow-haskell-users/2014-April/024920.html

他的想法是可以用 ghc > -i 选项:

  ghc -iDatabase.M = M 

,然后 M 文件夹中的任何内容都将被视为 Database.M



你也可以把新的选项在 .cabal 文件中的 hs-source-dirs 字段中。



然而,对提案有各种反对意见,所以他现在就撤回了。主要问题在于它增加了复杂性,还需要更改其他几个工具(例如 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 ?

解决方案

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.

这篇关于导出具有不同层次结构的haskell模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆