GHCI配置文件可以使用CPP宏吗? [英] Can a GHCI config file use CPP macros?
问题描述
我认为设置全局GHCI配置是很好的,这样我的常用导入就会在提供它们的包出现时自动发生。我试着把它加入〜/ .ghc / ghci.conf
:
:set -XCPP
#ifdef MIN_VERSION_containers
导入Data.Set(Set)
导入限定数据集Set as
import Data.Map(Map)
将合格的Data.Map导入为Map
#endif
但显然这并不工作。
> stack repl
使用以下软件包配置GHCi:
GHCi,版本8.0.2:http://www.haskell.org/ghc/:? for help
< interactive>:24:1:error:输入'#'的分析错误
< interactive>:29:1:error:parse error on输入'#'
有没有办法让CPP宏运行或者其他方式来完成我试图做什么?
GHCI不能直接使用这些宏,但它们 em>在您使用的文件中使用 GHCI's :add
命令。
例如,这就是我现在的设置看起来像:
〜/ .ghc / ghci.conf
包含:add
命令: > grep imports〜/ .ghc / ghci.conf
:add /home/chris/.ghc/imports.hs
〜/ .ghc / imports / imports.hs
包含我的CPP进口:
> cat〜/ .ghc / imports / imports.hs
{ - #LANGUAGE CPP# - }
#ifdef MIN_VERSION_containers
import Data.Set(Set)
import合格Data.Set as Set
导入Data.Map(Map)
将合格的Data.Map导入为Map
#endif
I was thinking it would be nice to set up my global GHCI config such that my commonly-used imports occur automatically when the packages that provide them are present.
I tried adding this to ~/.ghc/ghci.conf
:
:set -XCPP
#ifdef MIN_VERSION_containers
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Map (Map)
import qualified Data.Map as Map
#endif
But apparently that does not work.
> stack repl
Configuring GHCi with the following packages:
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
<interactive>:24:1: error: parse error on input ‘#’
<interactive>:29:1: error: parse error on input ‘#’
Is there a way to get CPP macros to work, or some other way to accomplish what I'm trying to do?
Those macros cannot be used directly by GHCI, but they can be used in a file you include using GHCI's :add
command.
For example, this is what my setup now looks like:
~/.ghc/ghci.conf
contains the:add
command:> grep imports ~/.ghc/ghci.conf :add /home/chris/.ghc/imports.hs
~/.ghc/imports/imports.hs
contains my CPP'ed imports:> cat ~/.ghc/imports/imports.hs {-# LANGUAGE CPP #-} #ifdef MIN_VERSION_containers import Data.Set (Set) import qualified Data.Set as Set import Data.Map (Map) import qualified Data.Map as Map #endif
这篇关于GHCI配置文件可以使用CPP宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!