0

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"

2
  • If I read that correctly, you want to simply build your program? Then the command is ghc, not ghci, but I'd recommend you use cabal instead. Commented Jun 14, 2017 at 8:42
  • I don't think using cabal is a good idea when you are just working through the examples in LYAH. I would definitely avoid that until you need to build a project with additional library dependencies. Commented Jun 15, 2017 at 11:46

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for the help. You were exactly right and it fixed my problem. I am reading from the physical book and it doesn't have in it that note about Linux. Thanks for putting me straight. And kudos to you for actually understanding what I needed help with, wasn't sure anybody could understand my babbling.
Cool. Glad you got it working. Perhaps the author added that to the digital version after similar confusion elsewhere.
1

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.