使模块层次结构
我试图在Haskell中第一次构建一个独立程序,并且无法弄清楚如何获得ghc - 与我所喜欢的目录组织一起工作。 正如我有以下树的那一刻:
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
Affine.hs
module Affine (
  affineEnc,
  affineDec,
  ) where
Shift.hs
module Shift (
  shiftEnc,
  shiftDec
  ) where
import Affine
Substitution.hs
module Substitution (
  substitutionEnc,
  substitutionDec,
  ) where
基于此 - https://en.wikibooks.org/wiki/Haskell/Standalone_programs - 在我看来,以下命令应该至少妥善处理主要的进口,虽然我不清楚HCTests中的进口是否可以工作(在我看来,如果我正确读取它 - 指定“向上树”Haskell模块 - 他们应该)。
我在基础目录中运行的命令是:
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'
所以我的假设是我会通过以下方式解决这个问题:
Substitution.hs
module Ciphers.Substitution (
  substitutionEnc,
  substitutionDec,
  ) where
我的问题是,如何才能处理Shift.hs需要导入Affine.hs,而我仍然需要Ciphers.Shift和Ciphers.Affine?
  您不能将命令行选项-i和搜索路径与空白分开,因为-i以下空格将重置搜索路径。 
使用
ghc -O2 --make -isrc -o crypto Main.hs
要么
ghc -O2 --make -i./src -o crypto Main.hs
代替。
链接地址: http://www.djcxy.com/p/43425.html下一篇: Need a tutorial for using GHC to parse and typecheck Haskell
