是否可以将 cpp 预处理器与 haskell 堆栈一起使用

Is it possible to use cpp preprocessors with haskell stack

是否可以将 cpp 预处理器与 haskell 堆栈一起使用,

例如:

{-# LANGUAGE CPP #-}
module MyModule (
  main
  #ifdef TEST
    ,functionUnderTest
    ,functionAlsoUnderTest
  #endif
  ) where ....

对于 cabal,.cabal 中的以下设置似乎有效: cpp-options: -DTEST 可以用堆栈重现吗?

来自wiki, this answer here on SO and also this github issue

flags

Flags can be set for each package separately, e.g.

flags:   package-name:
    flag-name: true

Flags will only affect packages in your packages and extra-deps settings. Packages that come from the snapshot global database are not affected.

或者,您可以在使用 --flag 调用堆栈时直接传递标志,我假设语法类似于

stack test --flag project:TEST