简体   繁体   English

将.hs文件作为脚本运行时如何导入相邻模块

[英]How to import adjacent module when running .hs file as script

I was following the directions here: https://haskell.fpcomplete.com/tutorial/stack-script 我正在按照这里的指示进行操作: https : //haskell.fpcomplete.com/tutorial/stack-script

I have a cabal/stack project with this file structure: 我有一个具有此文件结构的cabal / stack项目:

app/Main.hs
src/Lib.hs

I can run Main.hs with: 我可以使用以下命令运行Main.hs:

stack runghc -- app/Main.hs 

that works if Main.hs does not import Lib.hs, but if it does, I get this error: 如果Main.hs不导入Lib.hs,则可以正常工作,但如果可以,则出现此错误:

app/Main.hs:3:1: error:
    Ambiguous module name ‘Lib’:
      it was found in multiple packages:
      haskell-starter-0.1.0.0 libiserv-8.6.3
  |
3 | import Lib
  | ^^^^^^^^^^

is there anyway to include the src/Lib.hs file in the build? 无论如何在构建中包括src / Lib.hs文件? For a package it would look like: 对于软件包,它看起来像:

stack runghc --package xyz -- app/Main.hs 

but what about for a module or file? 但是模块或文件呢? Something like: 就像是:

stack runghc --module src/Lib.hs -- app/Main.hs 

?

Update : So I tried this: 更新 :所以我尝试了这个:

stack runghc -- -i src/* app/Main.hs

And I got: 我得到:

 src/Lib.hs:0:66: error: • Variable not in scope: main :: IO a0 • Perhaps you meant 'min' (imported from Prelude) 

You need to pass runghc the -i option to tell it about include paths. 您需要传递runghc -i选项以告知它包含路径。 The following should work: 以下应该工作:

stack runghc -- -isrc app/Main.hs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM