The post, Haskell and Eclipse, outlines how to set up the Haskell plugin in Eclipse. This is a follow up, illustrating how to get started developing in Haskell now that you have an IDE to work with.
Let's begin with just starting Eclipse and looking at some of what we have to work with as shown in Fig. 1.
In order to start working with code, you need to create a project. Under the Navigator tab, right click and select New to see the options as shown in Fig. 2. Choose:
Haskell Project -> Name the project -> Select where to save it -> Finish Fig. 2 - 4 walk through this stage.
Now take a look at the structure of the project you created. The src directory is where you will put your Haskell files. With the src directory selected, choose New and you will be given several options as to the type of files (or even a sub-project) you can create. See Fig. 5.
Mostly, you will either create a Haskell Module or a standalone Haskell file. To create the standalone file, choose File, give it a name and the extension .hs.
NOTE: Both module and standalone file names should start with an uppercase letter. For example, I will create a new Haskell source file called AddIntList as shown in Fig. 6.
For example, I will add code to the file to sum a list of integers. Once done, simply follow the points on the list which is also shown in Fig. 7.
- Highlight all the code
- Right click
- Select Run As
- Choose the compiler to use (I have GHC installed so pick GHCi)
NOTE: If you started a new project and then added a file rather than a new module, to compile, right-click and choose Run As on the actual project folder in the Navigation Pane, then when the GHCi window in Eclipse shows that the module loaded message (Ok, modules loaded:), then type in the name of the function and pass the arguments along as well.
The code used for this demo is as follows:
addIntList x = foldl (+) 0 x
Once the code has successfully been compiled, you will see a message in the Console window indicating that. At the prompt, you can just type in the function you want to execute with arguments and hit enter as shown in Fig. 8.
Happy coding!
4 comments:
Could you paste in your code for the AddIntList exemple. Iam having some trouble getting the interactive GHCI window in the console window in eclipse.
Sorry about that, a while ago I was messing with Picasa and it deleted some of the images. I have added them back in as well as the little code snippet. Also I made a note about compiling a module vs. a new haskell file in eclipse. Let me know if you still have any issues getting it all to work.
Hi,
thanks for the fast reply. It works now, but i used eclipse 3.5 EE edition and it didnot work with it.(I didnt get the GHCi in the console window(it did create a .exe file)). I downloaded the eclipse 3.4.1 Classic that you used and it worked fine with that.
no problem :-) I am glad you have it up and running
Post a Comment