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.