在 OPTIONS pragma 中设置导入路径

Setting import path in an OPTIONS pragma

根据 GHC 8.4.3 flag reference, the -i flag is dynamic, which means it should be settable by an OPTIONS pragma.

所以我尝试了以下方法:

.
├── Main.hs
└── imp
    └── Imported.hs

imp/Imported.hs 的内容:

module Imported (foo) where

foo :: String
foo = "Foo"

Main.hs 的内容:

{-# OPTIONS_GHC -iimp #-}
import Imported (foo)

main :: IO ()
main = putStrLn foo

但是,如果我尝试使用 runhaskell 运行 Main.hs,它会抱怨找不到 Imported

$ runhaskell -v Main.hs
...
Main.hs:2:1: error:
    Could not find module ‘Imported’
    Locations searched:
      Imported.hs
      Imported.lhs
      Imported.hsig
      Imported.lhsig

如何在 OPTIONS 编译指示中指定 -i 标志?

这似乎是 2007 年 fixed 的文档错误的回归,然后在 2014 年将一堆 "static" 更改为 "dynamic" 时重新破坏在标志参考 table 中。根据链接的错误报告,-i 标志不是完全动态的。在 GHCi 中可以是 :set 但不能在 OPTIONS_GHC 行中指定。