修改Emacs较差的Haskell进程以启用CPP处理 [英] Modifying Emacs Inferior Haskell processes to enable CPP processing

查看:109
本文介绍了修改Emacs较差的Haskell进程以启用CPP处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  ghci -cpp Random.hs 

或者可以做:

  ghci -cpp 

然后从ghci:

 前奏GOA> :load Random 
[1 of 1]编译System.Random(Random.hs,解释)
好​​的,加载的模块:System.Random。

如果我使用Emacs Inferior Haskell模式( Emacs / Inferior Haskell进程),我有
来源:

  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命令:

  Cc Cl 

这是 lower-haskell-load-file ,ghci在子窗口中打开在emacs。但是,如果从这个窗口中输入加载Random.hs 然后我收到错误消息:

  *主GOA> :load Random.hs 

Random.hs:1:2:字符'i'上的词法错误
失败,加载模块:无。

如何加载 Random.hs 考虑到cpp扩展?或者如何修改 haskell-mode / inf-haskell.el ,以便在键入 Cc Cl 时使用 -cpp 选项调用ghci,以便命令:load Random.hs 可以执行没有错误?

解决方案

可靠的方式肯定是在文件头中请求 CPP 以及其他扩展名:

  { - #LANGUAGE CPP# - } 

#if __GLASGOW_HASKELL__> = 701
{ - #LANGUAGE值得信赖# - }
#endif

---------------------------------------------- -------------------------------
- |
- 模块:System.Random
- 版权所有:(c)格拉斯哥大学2001
- 许可证:BSD样式(请参阅随机存储库中的文件LICENSE)

随机包只会在 .cabal 文件。



最简单的方式可能是简单地转动 CCP 永久在所有ghci会话中,添加

 :set -XCPP 

到您的〜/ .ghci 文件。 p>

If we look at the source of The random package we have a file Random.hs. Because of CPP extensions one has to invoke ghci via the following command :

ghci -cpp Random.hs

Alternatively one can do :

ghci -cpp

and then from within ghci :

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

If I use Emacs Inferior Haskell mode (Emacs/Inferior Haskell processes) and I have the source :

module Main where
import System.Random

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

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

main = do
  print $ mymult 5

then upon typing the emacs command :

C-c C-l

which is inferior-haskell-load-file, ghci is opened in a subwindow in emacs. However if from within this window I type load Random.hs then I get the error message :

*Main GOA> :load Random.hs

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

How can I load Random.hs taking into account cpp extensions? Or alternatively how do I modify haskell-mode/inf-haskell.el such that ghci is invoked with the -cpp option upon typing C-c C-l, so that the command :load Random.hs can be executed without error?

解决方案

The most reliable way is certainly to request CPP, along with other extensions, in the file header:

{-# 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)

The random package only does this in the .cabal file.

The easiest way might be to simply turn CCP on permanently in all ghci sessions, by adding

:set -XCPP

to your ~/.ghci file.

这篇关于修改Emacs较差的Haskell进程以启用CPP处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆