views:

1209

answers:

3

I'm having trouble getting "hello world" going with eclipseFP and Haskell.

I have the following code,

module Main where
  main = putStr "Hello world!"

and when I compile it with

ghc.exe .\H1.hs -o hw.exe

it works fine, but under eclipsePF, when I run it I only see the following in the console window:

GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main>

What noob mistake am I making?

+1  A: 

Never used eclipse but what you see is ghci, GHCi is GHC's interactive environment. Your module was loaded successfully in ghci, you can type main in ghci to run the function main of your program, actually you can call any function of your program that way.

hiena
+3  A: 

I haven't used EclpiseFP in years, so bear that in mind.

What appears to be happening is that EclipseFP is loading GHCi in the console. GHCi is an interactive Haskell shell, in which you can evaluate simple expressions. It also apparently loaded your module Main, so you can use GHCi to call functions in your module.

If you type in :main in the console, it will run you program and print "Hello world!", you could also call other functions you define in your program or standard Haskell functions.

However, what you may want to do is set EclipseFP to execute your program when you run, and I can't remember how to do that, probably somewhere in the "Run" menu.

Tom Lokhorst
I think it's "main" without the colon
yairchu
Typing `main` will simply call the main function (that will work). However, typing `:main` allows you to pass arguments which can be read with `getArgs`, often useful for commandline programs.
Tom Lokhorst
+4  A: 

From what little I've seen of EclipseFP, it's merely an interface for GHCi. Which means, as far as I'm concerned, that there's no reason to use it, since you get all the bad of Eclipse (the bloat, the bottomless thirst for memory, the tortoise-on-sedatives speed), with absolutely none of the good (the indexing, the debugger, the management of your tool stack).

So what noob mistake did you make? You used Eclipse. It's OK -- an easy mistake to make. If you were learning Scala, Eclipse might have been the way to go. But with Haskell, you're better off running GHCi from the command line and using an editor like Notepad++ (which has decent syntax highlighting). For once, the command-line/editor combination is preferable not because it's macho, but because it's more useful.

If you absolutely must have an IDE, the pickings are few right now, but here's what I've found.

Leksah
WinGHCi

And of course, any found in the answer to this question.

I haven't used it, but Leksah seems to be the most feature-rich IDE to date. Personally, I'm sticking with Notepad++ and the command line.

rtperson
-1: You didn't answer the question. Eclipse or no Eclipse, the solution would be the same, as the other answers describe.
Jørgen Fogh
@Jørgen: Well, the OP seemed to appreciate my answer, so I'll take your kibbitzing with a grain of salt. But I don't think it's out of line to question the utility of a plugin that isn't able to so much as run an executable *when it's asked to do so*. Eclipse is very much the issue here.
rtperson