简体   繁体   中英

Running a haskell program in ghci

I am new to Haskell and trying to learn it from "Learn you a 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. 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?

I have tried... $ ./program --make program --make program.exe and about a thousand variations of these things. 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

cmd "Assembler failure"

Haskell can be compiled or interpreted. To use a python-like interpreter do runhaskell and you can use the same parameters as you would compile it.

More information here: What's the difference between runghc and runhaskell?

It looks like you got confused between ghci and the command line. You can only type Haskell code in ghci. The command ./capslocker < haiku.txt is meant to be run from the command line and will run your compiled program capslocker . The $ sign is the command prompt in Linux and you're not meant to type that in. The book suggests using

$ ghc --make capslocker 

beforehand to compile the code. It doesn't actually use ghci in this section. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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