【问题标题】:ghc --make module hierarchyghc --make 模块层次结构
【发布时间】:2014-04-07 15:01:09
【问题描述】:

我第一次尝试在 Haskell 中构建一个独立的程序,但在弄清楚如何让 ghc --make 与我喜欢的目录组织一起工作时遇到了麻烦。目前我有以下树:

readme.md
src/
  Main.hs
  Ciphers/
    Affine.hs
    Shift.hs
    Substitution.hs
  Tests/
    HCTests.hs

使用以下导入:

Main.hs:

 module Main where

 import Tests.HCTests
 import Ciphers.Affine
 import Ciphers.Shift
 import Ciphers.Substitution

HCTests.hs

module Tests.HCTests (unitTests) where

import Ciphers.Substitution
import Ciphers.Affine
import Ciphers.Shift

仿射.hs

module Affine (
  affineEnc,
  affineDec,
  ) where

Shift.hs

module Shift (
  shiftEnc,
  shiftDec
  ) where

import Affine

替换.hs

module Substitution (
  substitutionEnc,
  substitutionDec,
  ) where

基于此 - https://en.wikibooks.org/wiki/Haskell/Standalone_programs - 在我看来,以下命令至少应该正确处理 main 中的导入,尽管我不清楚 HCTests 中的导入是否会起作用(在我看来,如果我正确阅读了这个- Specifying "Up The Tree" Haskell Modules - 他们应该)。

我在基本目录中运行的命令是:

ghc -O2 --make -i src -o crypto Main.hs

因错误而失败:

target `src' is not a module name or a source file

编辑

我还有一个问题。感谢 Zeta 的回答,我已经把它排序了,但是当我运行它时,我收到以下错误:

src/Ciphers/Substitution.hs:5:8:
    File name does not match module name:
    Saw: `Substitution'
    Expected: `Ciphers.Substitution'

所以我的假设是我会通过以下方式解决这个问题:

替换.hs

module Ciphers.Substitution (
  substitutionEnc,
  substitutionDec,
  ) where

我的问题是如何处理 Shift.hs 需要导入 Affine.hs,而我仍然需要 Ciphers.Shift 和 Ciphers.Affine?

【问题讨论】:

  • 正如 Zeta 的回答所指出的,Wikibook 中有一个错字。现在已修复。
  • 实际上,在 Shift.hs 中导入 Ciphers.Affine 似乎有效。当我试图在没有 make 的情况下简单地编译 Affine.hs 时,它之前抛出了一个错误。

标签: haskell ghc


【解决方案1】:

您不能将命令行选项-i 和搜索路径用空格分开,因为-i 与后面的空格重置 search path

使用

ghc -O2 --make -isrc -o crypto Main.hs

ghc -O2 --make -i./src -o crypto Main.hs

改为。

【讨论】:

  • 没关系,我有一个已编辑的问题,我将附加到主要问题,此评论无效。
  • @JackGibbs:如果编辑显着改变了您的问题,通常最好发布一个新问题。但我们会在编辑后看到。
  • @JackGibbs 您的模块名称应与目录结构匹配,因此应为Ciphers.AffineCiphers.Substitution 等。
  • 我不认为它做了那么多,它沿着相同的路线(而且我认为适合在同一个标​​题下),事实上在 duplode 的评论中是正确的。
猜你喜欢
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
  • 2019-11-20
  • 2013-02-20
  • 2023-02-14
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
相关资源
最近更新 更多