Haskell模块命名约定 [英] Haskell module naming conventions
问题描述
我应该如何命名我的Haskell模块作为程序而不是库,并将它们组织到层次结构中?
我正在拍摄名为Luminosity的光线追踪器。首先我有这些模块:
向量颜色相交跟踪渲染分析导出
每个模块本身都很好,但是我觉得这个组织没有。
首先,我将每个模块放在 Luminosity
下,例如 Vector
现在然后我想:Vector和Color是独立的,可以重用,所以它们应该是分离。但它们太小而无法转变成图书馆。
他们应该去哪里?已经(在hackage上)有一个 Data.Vector
和 Data.Colour
,所以我应该把它们放在那里?或者这会引起混淆(即使我将它们与其他本地进口分组在一起)?如果不存在,它应该是 Luminosity.Data.Vector
还是 Data.Luminosity.Vector
?我很确定我已经看到两个使用过,虽然也许我碰巧看到一个使用非传统结构的项目。
我也有一个简单的TGA图像导出器(导出
),它可以独立于亮度。它看起来正确的位置是 Codec.Image.TGA
,但是如果 Luminosity
在某处并且if所以,在哪里?
如果结构一个Haskell项目或其他wiki解释了这一点。 首先我把每个模块放在 Luminosity
我认为这是一个很好的举措。它澄清了任何人阅读代码,这些模块是专为 Luminosity
项目。
如果你编写一个模块,目的是模拟或改进现有的库,或者填补您认为某个特定类库缺失的缺口,然后在这种罕见情况下,删除前缀并将其命名为一般。有关此示例,请参阅管道软件包导出 Control.Monad .Trans.Free
,因为作者出于任何原因不满意Free monads的现有实现。
<然后我想,Vector和Color几乎是独立的,可以重用,所以它们应该分开。但他们正在向小型图书馆分类(分别为125和42行)。他们应该去哪里?
如果你没有创建一个单独的库,那么可能将它们放在亮度.Vector
和 Luminosity.Colour
。如果您确实创建了独立的库,那么请尝试通过电子邮件发送这些库的目标受众,并了解其他人如何认为这些库应该被命名和分类。不管你是否将它们拆分为单独的库,完全取决于你,以及你认为这些单独的库可能为其他人提供多少好处。
How should I name my Haskell modules for a program, not a library, and organize them in a hierarchy?
I'm making a ray tracer called Luminosity. First I had these modules:
Vector Colour Intersect Trace Render Parse Export
Each module was fine on it's own, but I felt like this lacked organization.
First, I put every module under Luminosity
, so for example Vector
was now Luminosity.Vector
(I assume this is standard for a haskell program?).
Then I thought: Vector and Colour are independent and could be reused, so they should be separated. But they're way too small to turn into libraries.
Where should they go? There is already (on hackage) a Data.Vector
and Data.Colour
, so should I put them there? Or will that cause confusion (even if I import them grouped with my other local imports)? If not there, should it be Luminosity.Data.Vector
or Data.Luminosity.Vector
? I'm pretty sure I've seen both used, although maybe I just happened to look at a project using a nonconventional structure.
I also have a simple TGA image exporter (Export
) which can be independent from Luminosity. It appears the correct location would be Codec.Image.TGA
, but again, should Luminosity
be in there somewhere and if so, where?
It would be nice if Structure of a Haskell project or some other wiki explained this.
First of all I put every module under
Luminosity
I think this was a good move. It clarifies to anyone that is reading the code that these modules were made specifically for the Luminosity
project.
If you write a module with the intent of simulating or improving upon an existing library, or of filling a gap where you believe a particular generic library is missing, then in that rare case, drop the prefix and name it generically. For an example of this, see how the pipes package exports Control.Monad.Trans.Free
, because the author was, for whatever reason, not satisfied with existing implementations of Free monads.
Then I thought, Vector and Colour are pretty much independent and could be reused, so they should be separated. But they're way to small to separate off into a library (125 and 42 lines respectively). Where should they go?
If you don't make a separate library, then probably leave them at Luminosity.Vector
and Luminosity.Colour
. If you do make separate libraries, then try emailing the target audience of those libraries and see how other people think these libraries should be named and categorized. Whether or not you split these out into separate libraries is entirely up to you and how much benefit you think these separate libraries might provide for other people.
这篇关于Haskell模块命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!