2017-02-18 38 views
4

我認爲這將是很好的,建立我的全球GHCI配置,使我的常用導入自動發生時,提供它們的包都存在。GHCI配置文件可以使用CPP宏嗎?

我嘗試添加這~/.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 

但顯然不起作用。

> 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 ‘#’ 

有沒有辦法讓CPP宏工作,或其他方式來實現我想要做的?

+0

我想那個.ghci就好像你在GHCi提示符下編寫了'#ifdef ...'一樣,沒有做任何事情。 – chi

回答

4

這些宏不能直接由GHCI使用,但它們可以使用在包含的文件中使用GHCI's :add command

例如,這是我的設置,現在看起來像:

  • ~/.ghc/ghci.conf包含:add命令:

    > grep imports ~/.ghc/ghci.conf 
    :add /home/chris/.ghc/imports.hs 
    
  • ~/.ghc/imports/imports.hs包含我CPP'ed進口:

    > 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 
    
+0

感謝[Tim Humphries](https://twitter.com/thumphriees/status/832752388888883201)解決方案。 –

相關問題