Carlos Scheidegger writes:
First, the Happy example uses some functions that exist in Hugs but not in GHC, like isAlpha, isDigit and isSpace (I think so, at least, because i type ':t isAlpha' in GHCi and get 'variable not in scope'), so I created a module called CharClasses with these functions.
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:
c:/ghc/ghc- 5.02/libHSstd.a(PrelMain__1.o)(.text+0x16)://c/tmp/ghc1756.hc: undefined reference to `__stginit_Main' c:/ghc/ghc- 5.02/libHSstd.a(PrelMain__2.o)(.text+0x4)://c/tmp/ghc1756.hc: undefined reference to `Main_main_closure' c:/ghc/ghc- 5.02/libHSstd.a(PrelMain__2.o)(.text+0x33)://c/tmp/ghc1756.hc: undefined reference to `Main_main_closure'
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 once. Any other call I get:
Happy> main *** Exception: illegal operation Action: hGetContents Handle: {loc=<stdin>,type=semi-closed,binary=False,buffering=line} 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 (CAF). Cheers, Simon