简体   繁体   English

在ghci中运行haskell程序

[英]Running a haskell program in ghci

I am new to Haskell and trying to learn it from "Learn you a Haskell." 我是Haskell的新手,正在尝试从“了解Haskell”中学习它。 I have run into a problem that I cannot find an answer to anywhere. 我遇到了一个找不到任何地方答案的问题。 I have a simple program that I want to run, but nothing will I do will make it run. 我有一个想要运行的简单程序,但是我什么也不会做使其运行。 What the book is telling me to do doesn't work. 这本书告诉我的事情行不通。 I can compile the program and run individual functions, but I can't get main to run unless I call that particular function. 我可以编译程序并运行各个函数,但是除非调用该特定函数,否则无法使main运行。 That seemed fine to me until I tried to pass a text file into it and it doesn't work. 在我尝试将文本文件传递给它之前,这对我来说似乎还不错,但是它不起作用。

So what do I do to run the program after typing :load program.hs? 那么,在键入:load program.hs之后我该怎么做才能运行该程序?

I have tried... $ ./program --make program --make program.exe and about a thousand variations of these things. 我已经尝试过... $ ./program --make program --make program.exe以及这些东西的大约一千种变化。 What the hell do I do to get my program running so that I can pass it a text file? 我该怎么办才能使程序运行,以便可以将其传递给文本文件? Picture of results in GHCi GHCi中的结果图片

cmd "Assembler failure" cmd“汇编程序失败”

Haskell can be compiled or interpreted. Haskell可以被编译或解释。 To use a python-like interpreter do runhaskell and you can use the same parameters as you would compile it. 要使用类似python的解释器,请执行runhaskell并且可以使用与编译时相同的参数。

More information here: What's the difference between runghc and runhaskell? 这里的更多信息: runghc和runhaskell有什么区别?

It looks like you got confused between ghci and the command line. 看来您在ghci和命令行之间感到困惑。 You can only type Haskell code in ghci. 您只能在ghci中输入Haskell代码。 The command ./capslocker < haiku.txt is meant to be run from the command line and will run your compiled program capslocker . 命令./capslocker < haiku.txt是要从命令行运行的,它将运行已编译的程序capslocker The $ sign is the command prompt in Linux and you're not meant to type that in. The book suggests using $符号是Linux中的命令提示符,您无意键入该符号。该书建议使用

$ ghc --make capslocker 

beforehand to compile the code. 事先编译代码。 It doesn't actually use ghci in this section. 在本节中,它实际上并未使用ghci If you're on Windows then some of the commands may not work, since it assumes you are using Linux (it explains this earlier in the "input and output" section and suggests cygwin as an alternative). 如果您使用的是Windows,则某些命令可能无法使用,因为它假定您使用的是Linux(在“输入和输出”部分中对此进行了解释,并建议使用cygwin作为替代方法)。

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

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