GHC doesn't compile Happy example
Tue, 2 Oct 2001 12:09:14 +0100
Carlos Scheidegger writes:
> First, the Happy example uses some functions that exist in=20
> Hugs but not in GHC, like isAlpha, isDigit and isSpace (I think so,=20
> at least, because i type ':t isAlpha' in GHCi and get=20
> 'variable not in=20
> scope'), so I created a module called CharClasses with these=20
This is a long-standing known bug in Hugs. These functions are
available from the Char module.
> So, I ran happy and generated calc.hs without any problems.
> When I try to compile calc.hs, by doing
> ghc -o calc.exe calc.hs CharClasses.hs
> I get:
> undefined reference to `__stginit_Main'
> undefined reference to `Main_main_closure'
> undefined reference to `Main_main_closure'=20
It looks like perhaps the calc.hs module isn't declared as module Main.
> Another strange behavior is that I can only call the main function=20
> once. Any other call I get:
> Happy> main
> *** Exception: illegal operation
> Action: hGetContents
> Handle: =
> Reason: handle is closed
> File: <stdin>
This is the defined behaviour of getContents: it puts the stdin Handle
in a state known as "semi-closed", wherein any further I/O operations on
it are forbidden. Because I/O state is retained between computations,
the semi-closed state persists until the next :load or :reload command.
You can make these handles reset themselves after every evaluation by
giving GHCi the command ':set +r'. This works because stdin, stdout and
stderr are just top-level expressions that can be reverted to their
unevaluated state in the same way as any other top-level expression