Haskell 如何在cabal/stack中添加CPP定义?

Haskell 如何在cabal/stack中添加CPP定义?,haskell,cabal,haskell-stack,Haskell,Cabal,Haskell Stack,我正在学习以下模块: 其内容包括: module Text.PrettyPrint.Boxes ( -- * Constructing boxes #ifdef TESTING Box(Box, content) #else Box #endif 如何启用/定义测试值-用于开发目的?理想情况下,我希望在GHCi会话中构建/启用此功能。我必须纠正自己-我给出的评论完全错误 > git clone git://github.com/treeowl/boxes.

我正在学习以下模块:

其内容包括:

module Text.PrettyPrint.Boxes
    ( -- * Constructing boxes
#ifdef TESTING
      Box(Box, content)
#else
      Box
#endif

如何启用/定义
测试
值-用于开发目的?理想情况下,我希望在GHCi会话中构建/启用此功能。

我必须纠正自己-我给出的评论完全错误

> git clone git://github.com/treeowl/boxes.git
> cd boxes
> stack init
> stack ghci --ghc-options=-DTESTING
split-0.2.3.2: using precompiled package
boxes-0.1.4: configure (lib)
Configuring boxes-0.1.4...
boxes-0.1.4: initial-build-steps (lib)
Completed 2 action(s).
Configuring GHCi with the following packages: boxes
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from ...
[1 of 1] Compiling Text.PrettyPrint.Boxes ( .../boxes/Text/PrettyPrint/Boxes.hs, interpreted )
Ok, modules loaded: Text.PrettyPrint.Boxes.
Loaded GHCi configuration from /tmp/ghci28386/ghci-script
*Text.PrettyPrint.Boxes Text.PrettyPrint.Boxes> :t content 
content :: Box -> Content

工作正常。

如果调用
堆栈测试
则会自动设置标志-目前没有cabal标志来启用此CPP标志。这似乎仅在
项目中调用
堆栈ghci
时有效,而不是在通过cabal将其作为依赖项包含时有效。您可以向Box和Box发送拉取请求提供一个阴谋集团标志,并使用您的github回购协议。同时,stack内置了使用回购协议作为源的选项;对于cabal,我已经有一段时间没有使用它了,所以我不知道这是否是一个选项。如果您需要
内容
功能用于测试目的以外的其他目的-我会询问维护人员隐藏该功能的意图!有很多东西很方便,但使用时会增加一些风险。