You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Stack共享模块?配置package.yaml实现跨目录模块引用

解决方法

要让benchmarks目录下的Investigate.hs能导入test目录的Example1模块,你需要修改package.yaml中benchmarks部分的配置,让该benchmark目标能访问test目录的源码:

  • 给benchmarks下的investigate条目添加source-dirs,包含benchmarks和test两个目录
  • 可调整main路径(因为source-dirs包含benchmarks后,直接写Investigate.hs即可,原路径benchmarks/Investigate.hs也可保留)

修改后的完整package.yaml(简化版)如下:

name: proj

dependencies:
- base >= 4.7 && < 5

library:
  source-dirs: src

executables:
  proj-exe:
    main: Main.hs
    source-dirs: app
    dependencies: proj

tests:
  proj-test:
    main: Spec.hs
    source-dirs: test
    dependencies: proj

benchmarks:
  investigate:
    main: Investigate.hs
    source-dirs:
      - benchmarks
      - test
    dependencies: proj

配置完成后,Stack在构建benchmark时会同时加载benchmarks和test目录的源码,Investigate.hs里就能直接导入Example1模块。

内容的提问来源于stack exchange,提问作者thirsty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 01:15:39