【问题标题】:Modifying Emacs Inferior Haskell processes to enable CPP processing修改 Emacs Inferior Haskell 进程以启用 CPP 处理
【发布时间】:2014-05-31 14:52:47
【问题描述】:

如果我们查看The random package 的来源,我们有一个文件Random.hs。由于 CPP 扩展,必须通过以下命令调用 ghci:

ghci -cpp Random.hs

另外一个可以做:

ghci -cpp

然后从 ghci 内部:

Prelude GOA> :load Random
[1 of 1] Compiling System.Random    ( Random.hs, interpreted )
Ok, modules loaded: System.Random.

如果我使用 Emacs Inferior Haskell 模式 (Emacs/Inferior Haskell processes) 并且我有 来源:

module Main where
import System.Random

gen = (random (mkStdGen 0)) :: (Bool,StdGen)

mymult :: Int -> Int
mymult x = 2 * x

main = do
  print $ mymult 5

然后在输入 emacs 命令时:

C-c C-l

inferior-haskell-load-file,ghci 在 emacs 的子窗口中打开。但是,如果在此窗口中输入 load Random.hs,则会收到错误消息:

*Main GOA> :load Random.hs

Random.hs:1:2: lexical error at character 'i'
Failed, modules loaded: none.

如何在考虑 cpp 扩展的情况下加载 Random.hs?或者,我如何修改haskell-mode/inf-haskell.el,以便在键入C-c C-l 时使用-cpp 选项调用ghci,以便可以无错误地执行命令:load Random.hs

【问题讨论】:

  • 当我执行:load Random.hs 时,我没有收到错误消息。在您提供的示例代码中,我看不出您需要-cpp 作为ghci 的选项的任何原因。在没有选项本身的情况下调用它对我有用。
  • @Sibi 你的意思是你可以在hackage.haskell.org/package/random的zip文件中加载Random.hs而不需要任何cpp选项?

标签: haskell emacs ghci


【解决方案1】:

最可靠的方法当然是在文件头中请求CPP,以及其他扩展名:

{-# LANGUAGE CPP         #-}

#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Trustworthy #-}
#endif

-----------------------------------------------------------------------------
-- |
-- Module      :  System.Random
-- Copyright   :  (c) The University of Glasgow 2001
-- License     :  BSD-style (see the file LICENSE in the 'random' repository)

random 包仅在 .cabal 文件中执行此操作。

最简单的方法可能是简单地在所有 ghci 会话中永久打开 CCP,方法是添加

:set -XCPP

到您的~/.ghci 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多