通过Emacs评估ghci或拥抱中的缓冲区 [英] Evaluate buffer in ghci or hugs via Emacs
问题描述
C-c C-b
将缓冲区内容直接发送到较差的SML进程。现在我只想和Haskell做同样的事情。 Haskell模式似乎不支持这一点,所以我想知道:Emacs和Haskell的正确方法是什么? 学习SML时,我一直使用 Cc Cb
几乎不停地轻松地评估我的程序,当我走,立即看到分配值的结果等等。但是如果我在包含两行的保存文件中的haskell模式中使用 Cc Cl
, let foo = foo
和 let bar =bar
- 我得到解析错误(可能不正确的缩进)
我认为你正在做一个常见的菜鸟错误,混淆你可以在ghci的副本中写什么以及您在haskell源文件中写的内容。
所有的sml解释器都是以这样一种方式进行的,您可以将任何顶级声明写入repl中,换句话说:任何您可以在sml文件中写入你可以写入sml解释器。因此,您可以将 val foo =bar
写入文件,并使用 Cc Cb
加载文件,您可以将 val foo =bar
放入解释器。
另一方面,由于haskell的工作原理,您可以将 let foo = 42
写入ghci,但它不是有效的顶级声明,因此这不能在一个haskell源文件(通过它自己)。另一方面,您可以在haskell源文件中使用 id n = n
,并使用 Cc Cl
加载文件,但是您不能直接将其写入ghci(您将收到错误:1:6:输入'='时的解析错误)。这样做的原因是ghci中的repl在IO monad中运行,因此,您写入ghci的内容必须使用符号来完成。我只能建议您从提供的互动评估中查看使用GHCi用户指南。
cc Cb
在sml模式是完全相同的 Cc Cl
在haskell模式,至少在概念上。我不太了解haskell模式的内部,但是在sml模式中,code> Cc Cb 在解释器中执行一些sml代码,通常是使用(...)
函数。在haskell模式下,似乎只是排除了:load...
ghci命令
Using sml-mode in Emacs I have been able to send my buffer contents directly to an inferior SML process using C-c C-b
. Now I want to do the same thing only with Haskell. Haskell-mode does not seem to support this, so I'm wondering: What is the right way to go about this with Emacs and Haskell?
While learning SML I've been using C-c C-b
almost non-stop to easily evaluate my program as I go, instantly seeing the results of assigning values etc. But if I use C-c C-l
in haskell-mode on a saved file containing two lines, let foo = "foo"
and let bar = "bar"
- I get "parse error (possibly incorrect indentation)"
I think you are making a common rookie mistake, confusing what you can write inside the repl of ghci and what you write in a haskell source file.
All sml interpreters are made in such a way that you can write any top level declaration into the repl, or put in other words: anything you can write in an sml file, you can write into the sml interpreter. Thus you are allowed to write val foo = "bar"
into a file and use C-c C-b
to load the file and you are allowed to just put in val foo = "bar"
into the interpreter.
On the other hand, because of how haskell work, you can write let foo = 42
into ghci, however it is not a valid top level declaration and thus this can't be in a haskell source file (by it self). On the other hand you can have id n = n
in a haskell source file and use C-c C-l
to load the file, however you can't write this directly into ghci (you will get an error: :1:6: parse error on input '='). The reason for this is that the repl in ghci runs in the IO monad, and thus what ever you write into ghci must be done using the do notation. I can only recommend that you read Interactive evaluation at the prompt from the Using GHCi user guide.
C-c C-b
in sml-mode is the exact same thing as C-c C-l
in haskell-mode, well atleast conceptually. I don't know that much about the internals of haskell-mode, but in sml-mode C-c C-b
executes some sml code in the interpreter, normally the use(...)
function. In haskell-mode it seems to just excute the :load "..."
ghci command
这篇关于通过Emacs评估ghci或拥抱中的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!