简体   繁体   English

在终端打开带有ghci的.hs文件?

[英]Opening a .hs file with ghci in Terminal?

I'm using Mountain Lion. 我正在使用Mountain Lion。 I open the terminal, then I load ghci , I write :l and then I try to load my file (which is in my desktop) by dragging it with the mouse from my desktop to the terminal, so I know that the location is correct and I get this, thank you in advance: 我打开终端,然后我加载ghci ,我写:l然后我尝试通过鼠标从我的桌面拖到终端来加载我的文件(在我的桌面),所以我知道位置是正确的我明白了,谢谢你:

Prelude> :l  /Users/myusername/Desktop/Test.hs 
[1 of 1] Compiling Main             ( /Users/myusername/Desktop/Test.hs, interpreted )

/Users/myusername/Desktop/Test.hs:1:7: parse error on input `\'
Failed, modules loaded: none.
Prelude> 

Edit: The file Im trying to open (written in Text Edit) is: 编辑:我试图打开的文件(用文本编辑编写)是:

double :: Int -> Int
double x = x + x

TextEdit is not a plaintext editor (unlike eg Windows Notepad), so by default it will include formatting junk in your files that GHC obviously isn't happy about. TextEdit 不是纯文本编辑器(与Windows Notepad不同),因此默认情况下它会在文件中包含格式化垃圾,GHC显然不满意。 Apparently you can still use TextEdit if set up correctly , but it's quite recommendable to use a proper programming editor. 显然,如果设置正确你仍然可以使用TextEdit ,但是建议使用正确的编程编辑器。 Like any Unix, OSX comes with a vi flavour, which takes some time to get used to but isn't that hard and works fine; 像任何Unix一样,OSX带有vi风格,这需要一些时间来习惯但不是那么难并且工作正常; at least you can use it to check what's really in your file. 至少你可以用它来检查文件中的内容。

vi /Users/myusername/Desktop/Test.hs

or, even simpler 或者,甚至更简单

cat /Users/myusername/Desktop/Test.hs

will just give you the exact contents of your file. 只会告诉你文件的确切内容。

For the choice what editor to use best, consider this question . 要选择最适合使用的编辑器,请考虑这个问题

I tried the same procedure on Windows and it worked perfectly. 我在Windows上尝试了相同的程序,它运行得很好。

Have you tried to go to the directory inside GHCi and open it? 你有没有试过去GHCi里面的目录打开它?

The procedure would be: 程序将是:

Prelude> :cd /Users/myusername/Desktop/
Prelude> :l Test.hs

For me, copying/pasting the code you have posted, both situations worked on Windows. 对我来说,复制/粘贴你发布的代码,两种情况都适用于Windows。

The presence of a \\ implies you've got an RTF (rich text) file from TextEdit. 一个\\的存在意味着你有一个来自TextEdit的RTF(富文本)文件。 RTF is TextEdit's default, and it's a format that annotates plain text with information about text font, size, etc. RTF是TextEdit的默认格式,它是一种格式,用于提供有关文本字体,大小等信息的纯文本。

I'd recommend vi or emacs, but to fix your immediate problem, open the file in TextEdit and hit Cmd-Shift-t to convert your file to plain text. 我建议使用vi或emacs,但为了解决您的问题,请在TextEdit中打开文件并点击Cmd-Shift-t将文件转换为纯文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM