This document shows how you would create and run the 'Hello World' application in Eclipse with Haskell support. It also explains some of the main user interface elements in Eclipse. The focus is on helping developers who are not familiar with Eclipse to quickly get started with it as an IDE that supports Haskell development.
Note: This is work in progress, which means that some of the features described here may not yet be in place.
Open the Haskell Perspective
Eclipse makes use of a concept called Perspectives. Everything in the workspace is seen from such a Perspective. When you start Eclipse for the first time, the most basic of all Perspectives is open: the Resource Perspective, which handles just some basic file management and text editing. By openening the Haskell perspective, you activate everything that is Haskell-aware.
Select from the menu: Window > Open Perspective > Haskell. (You can also open the Haskell Perspective from a link on the Welcome page.)
Seen from the Haskell Perspective, a file is not just a file, but (if it has the correct extension) a Haskell source file, which means that you can open it with the Haskell source editor, you can compile it and run it with a Haskell interpreter (like HUGS) or as (e.g. with GHC) compiled and linked executable. The Perspective contains also some Views, which provide Haskell-specific information about the file which is currently opened in the editor (Outline View) or about the last build process (in the Console View).
You can switch and close Perspectives at any time from the vertical toolbar at the left of the workbench. If you have closed a Perspective or a View, you can re-open it from the menu Window > Open Perspective or Show View.
The workspace is organized into Projects (roughly: directories within the workspace directory).
Create a new project by selecting File > New > Project from the menu, expanding the Haskell icon, then choosing Haskell Project. Specify a project name and hit OK.
Specify a project name
Specify where you want the project to reside (default is inside your workspace
Specify some initial components to be created for you. The New Project wizard will auto generate a cabal file that will contain a reference to each component you select. You can choose to create an executable, a library, or both.
Add source files to the project source folder.
If you have selected "executable" in the new project wizard page, a
Main.hs
file should have been created for you.
Otherwise you can create a new Haskell module from the menu (File > New > Haskell > Haskell Module).
The second page of the wizard lets you choose in which component the module will be present. You can have a project with several components, and not all modules are present in all components.
If you give the files a Haskell-specific extension (like .hs
or .lhs
(for literate Haskell), you can open the files with
the Haskell source code editor from the Project Explorer
view.
Right-click the file and choose Open with >Haskell editor. Type some code.
You can configure the editor in the main Preferences Dialog: Select Window > Preferences from the menu and choose the General > Editors > Text Editors section.
Enter the code for your 'Hello world', e.g.
| |
Save. This will trigger the auto building, and you will see compiler errors (if there were errors in the build) in the Problems View. If no errors have occurred, the compiled object files and the linked executable should be in their respective folders. Auto building works incrementally, that is, only changed resources are built when you save again.
You can launch the compiled executable of your Haskell programs from within the IDE.
Running a program creates a new Launch configuration for that program. You can re-run a lauch configuration from the Run menu. Clicking the Run-icon re-launches always the last launched configuration.
If you choose Run ... from the menu, you get a dialog where you can edit launch configurations. For example, you may want to add parameters to the program launch.
Console input and output are handled by the Console View (at the bottom left of the workbench). You should see the 'Hello world' output appear there, and if your program takes console input, the Console View is where you can type in while developing.
You can right click on any Haskell module and choose Run GHCi session. This will open GHCi, the GHC interpreter, in a Eclipse console, and load all the required modules.
You can type in that console and have a full interactive session, modifying your modules in the Eclipse editors and running code in the console
The launch configuration options for interpreter sessions let you configure some automation features, like automatically reloading modules that you've saved in the editor.