[Haskell-cafe] Newbie question about using WinGHCi

Ivan Miljenovic ivan.miljenovic at gmail.com
Thu Jul 1 02:12:18 EDT 2010

On 1 July 2010 16:04, Christopher Tauss <ctauss1 at gmail.com> wrote:
> Hello -
> I just a day or so ago downloaded Hakell and am playing around with it, and
> I came upon this problem with WinGHCi:
> I am able to enter a multi-line "do" statement that works if I use brackets
> and semi-colon like so:
> Prelude> :{
> Prelude| let main2 = do {
> Prelude| putStrLn "Please enter your name: ";
> Prelude| name <- getLine;
> Prelude| putStrLn ("Hello, " ++ name ++ ", how are you?") }
> Prelude| :}
> Prelude> main2
> Please enter your name:
> CT
> Hello, CT, how are you?
> Prelude>
> Note there is no indentation.  This makes sense to me because the :{  :}
> just take all the lines in between and make it one line.
> But it seems to me to be IMPOSSIBLE to input this into WinGHCi using
> indentation like most of the code samples seem to do.
> Should I just be satisfied that it works using brackets/ semi-colons?  Or is
> there something obvious that I am missing that allows for indentation?

Typically, ghci (including WinGHCI) and Hugs are used to evaluate and
experiment with code, rather than writing it.  Write your actual code
in a file and load it with :load (or :l for short) into ghci.

In this sense, they aren't "real" REPLs in that you can't define new
data types, classes, etc. in them (you can write functions with a let
statement, but it gets cumbersome for long functions).

It might be better off thinking of the prompt as being individual
lines in a big do-block for a specialised version of the IO monad (in
the sense that normally just entering "5+4" wouldn't typecheck let
alone print the result, etc.).

> Thanks in advance. It's issues lik this that keep me up into the depths of
> night.

Hopefully you can now get to sleep ;-)

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list