make module hierarchy

I'm trying to build a standalone program for the first time in Haskell, and am having trouble figuring out how to get ghc --make working with the directory organization of my liking. As the moment I have the following tree:

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

With the following imports:

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

Based on this - https://en.wikibooks.org/wiki/Haskell/Standalone_programs - It seems to me the following command should at least properly handle the imports in main, although I'm unclear whether the imports in HCTests will work (it seems to me if I read this properly - Specifying "Up The Tree" Haskell Modules - they should).

The command, which I run in the base directory, is:

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

Fails with error:

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

Edit

I have an additional question. Thanks to Zeta's answer, I've got that sorted, however when I run it, I get the following error:

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

So my assumption is that I'd solve this via:

Substitution.hs

module Ciphers.Substitution (
  substitutionEnc,
  substitutionDec,
  ) where

My question is how then can I handle that Shift.hs needs to import Affine.hs, while I still want both Ciphers.Shift and Ciphers.Affine?


You may not separate the command line option -i and the search path with whitespace, since -i with following whitespace resets the search path.

Use

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

or

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

instead.

链接地址: http://www.djcxy.com/p/43426.html

上一篇: Ghc:部分编译Haskell代码?

下一篇: 使模块层次结构