Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GHCi Problems

22 views
Skip to first unread message

Liu Junfeng

unread,
Mar 20, 2003, 10:23:05 PM3/20/03
to
I find that Haskell interpreter is rather difficult to use:
1."f=3" is a legal statement in Haskell, i.e. define "f" as a constant
function, but a parse error occurs. "let f=3" is illegal, "let" and
"in" are used together, but it works in GHCi.
2. if I happen to print out an infinite list, I don't know how to
interrupt it, when press Ctrl+C, GHCi just quit.
3. I can't use "import" to import modules. There are many sub
directories in the imports directory, but I don't know how to import
libraries in concurrent, win32, util, lang and objectio. When I
installed GraghicsLib, I can't use it in GHC, for GHCi can't find the
SOEGraghics and Concurrent modules.

Aaron Denney

unread,
Mar 20, 2003, 10:47:33 PM3/20/03
to
On 20 Mar 2003 19:23:05 -0800, Liu Junfeng <ru...@163.com> wrote:
> I find that Haskell interpreter is rather difficult to use:
> 1."f=3" is a legal statement in Haskell, i.e. define "f" as a constant
> function, but a parse error occurs. "let f=3" is illegal, "let" and
> "in" are used together, but it works in GHCi.

GHCi doesn't directly let you enter Haskell statements. As you say,
you can write "let f = 3 in <expr>", and "let f = ..." is roughly a
shorthand for "let f = ... in <rest of program>".

> 2. if I happen to print out an infinite list, I don't know how to
> interrupt it, when press Ctrl+C, GHCi just quit.

Huh. Ctrl-C works for me (Linux/ia32). Judging from your next question,
I assume you're on win32, which I know nothing about.

> 3. I can't use "import" to import modules. There are many sub
> directories in the imports directory, but I don't know how to import
> libraries in concurrent, win32, util, lang and objectio. When I
> installed GraghicsLib, I can't use it in GHC, for GHCi can't find the
> SOEGraghics and Concurrent modules.

No, you can't use import. :load will work, and it should chase imports
in existing packages. GHCi is more oriented to trying out expressions
defined by existing files, rather than entering code.

ghci -package concurrent should let you access the Concurrent module, and
so forth.

--
Aaron Denney
-><-

Liu Junfeng

unread,
Mar 21, 2003, 3:34:05 AM3/21/03
to
wno...@ugcs.caltech.edu (Aaron Denney) wrote in message news:<slrnb7l2ql...@hork.ugcs.caltech.edu>...

> On 20 Mar 2003 19:23:05 -0800, Liu Junfeng <ru...@163.com> wrote:
> > I find that Haskell interpreter is rather difficult to use:
> > 1."f=3" is a legal statement in Haskell, i.e. define "f" as a constant
> > function, but a parse error occurs. "let f=3" is illegal, "let" and
> > "in" are used together, but it works in GHCi.
>
> GHCi doesn't directly let you enter Haskell statements.

Why not, the Python interpreter is a good example.

> you can write "let f = 3 in <expr>", and "let f = ..." is roughly a
> shorthand for "let f = ... in <rest of program>".
>
> > 2. if I happen to print out an infinite list, I don't know how to
> > interrupt it, when press Ctrl+C, GHCi just quit.
>
> Huh. Ctrl-C works for me (Linux/ia32). Judging from your next question,
> I assume you're on win32, which I know nothing about.

Yes, I'm using windowsXP, but Hugs doesn't have this bug.


>
> > 3. I can't use "import" to import modules. There are many sub
> > directories in the imports directory, but I don't know how to import
> > libraries in concurrent, win32, util, lang and objectio. When I
> > installed GraghicsLib, I can't use it in GHC, for GHCi can't find the
> > SOEGraghics and Concurrent modules.
>
> No, you can't use import. :load will work, and it should chase imports
> in existing packages. GHCi is more oriented to trying out expressions
> defined by existing files, rather than entering code.
>
> ghci -package concurrent should let you access the Concurrent module, and
> so forth.

if I want to use both Concurrent and Win32, I have to say:
ghci -package concurrent -package win32

when ghci is already opened, how to load package
and how can I use ghc to compile file using these packages?

Ketil Malde

unread,
Mar 21, 2003, 3:52:57 AM3/21/03
to
ru...@163.com (Liu Junfeng) writes:

> wno...@ugcs.caltech.edu (Aaron Denney) wrote in message news:<slrnb7l2ql...@hork.ugcs.caltech.edu>...
>> On 20 Mar 2003 19:23:05 -0800, Liu Junfeng <ru...@163.com> wrote:

>>> I find that Haskell interpreter is rather difficult to use:
>>> 1."f=3" is a legal statement in Haskell, i.e. define "f" as a
>>> constant function, but a parse error occurs. "let f=3" is illegal,
>>> "let" and "in" are used together, but it works in GHCi.

>> GHCi doesn't directly let you enter Haskell statements.

> Why not,

I've no idea if this is the reason, but I like to think about GHCi as
running the IO monad. So you can enter things like

x <- readFile "foo"

and actually have x be the contents of that file. Frankly, I don't
see the problem of using 'let' to assign values.

> the Python interpreter is a good example.

Do you actually use the interpreter to enter real programs? I always
use an editor for that, and I find GHCi at least as comfortable as the
Python interactive. (But I'm of course not a Python expert)

(Perhaps it'd be possible to have a (user defined?) command to edit a
function, which could, for instance, bring up an emacs window (using
gnuclient) with the correct file, narrowed to the appropriate
function?)

-kzm
--
If I haven't seen further, it is by standing in the footprints of giants

Christian Szegedy

unread,
Mar 21, 2003, 7:26:01 AM3/21/03
to
Liu Junfeng wrote:

> Why not, the Python interpreter is a good example.

Haskell and Pyhton are quite different languages.
E.g., in Haskell, the order of the definitions does not
is not significant.

Jerzy Karczmarczuk

unread,
Mar 21, 2003, 11:18:25 AM3/21/03
to
Liu Junfeng dialogs with Aaron Denney

>>>I find that Haskell interpreter is rather difficult to use:
>>>1."f=3" is a legal statement in Haskell, i.e. define "f" as a constant
>>>function, but a parse error occurs. "let f=3" is illegal, "let" and
>>>"in" are used together, but it works in GHCi.
>>
>>GHCi doesn't directly let you enter Haskell statements.
>
> Why not, the Python interpreter is a good example.
>
>>you can write "let f = 3 in <expr>", and "let f = ..." is roughly a
>>shorthand for "let f = ... in <rest of program>".

Dont compare the incomparable. Python is a straightforward compiler/
interpreter, like Scheme. You write something, it gets evaluated and
the world continues, if that something was a definition, the actual
environment gets updated.

In languages with a stricter typing discipline, and "functional purity",
which perform more global program analysis the situation is more
delicate. CAML, when you enter a new definition augments the current
environment by a new instance. Haskell "should" read a whole program,
*all* definitions in any order. But GHCi is a hybrid, an incremental
monadic IO layer which invokes the compiler. The 'let' without 'in'
works because in a sense you are always within a 'do' block.
It provides the sequencing.

Unless I am telling rubbish, which happens on average 2.72 times per
month.


Jerzy Karczmarczuk

Joachim Durchholz

unread,
Mar 21, 2003, 11:25:39 AM3/21/03
to
Jerzy Karczmarczuk wrote:
>
> Unless I am telling rubbish, which happens on average 2.72 times per
> month.

Since that's one of the 86.54% of made-up internet statistics, your
remaining quota for the month is 1.72 ;-)

Regards,
Joachim
--
This is not an official statement from my employer.

Aaron Denney

unread,
Mar 21, 2003, 4:38:11 PM3/21/03
to
On 21 Mar 2003 00:34:05 -0800, Liu Junfeng <ru...@163.com> wrote:
> if I want to use both Concurrent and Win32, I have to say:
> ghci -package concurrent -package win32

Exactly.

> when ghci is already opened, how to load package

:set -package <name>

> and how can I use ghc to compile file using these packages?

ghc -package <name> ... file.hs

Ronald Legere

unread,
Mar 28, 2003, 3:27:48 PM3/28/03
to
"let f = 3", without the in, is allowed in a "do" monad statement, and
so is allowed at the command prompt in GHCi
See this section in the manual:

http://haskell.cs.yale.edu/ghc/docs/5.04.3/html/users_guide/x1059.html
.


0 new messages