Hi there, hugs and ghc understand much the same, but a few (often subtle) differences remain. Since I'd be interested in developing code for both, I'm looking for a way to directly take care of these differences in my code. Ghc offers a commandline option '-cpp' which will allow for '#ifdef' and other preprocessor directives. When testing it, it worked ok. Hugs seems to offer a similar feature '-F<cmd>'. When testing it, however, it did not work. 'cpp' seems to be called, but it seems to leave characters in the code that can't be dealt w/ by hugs. Moreover, it seems to called on every input file (i.e. the prelude). --- snip --- till@atlan:~/tmp> hugs -Fcpp gammel.hs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-1999 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: February 2000 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Reading file "/usr/local/share/hugs/lib/Prelude.hs": Parsing ERROR "/usr/local/share/hugs/lib/Prelude.hs" (line 1): Syntax error in input (unexpected symbol "#") FATAL ERROR: Unable to load prelude --- snap --- When trying to remove the '#' etc. left in the code by giving '-P' to cpp it still doesn't work. --- snip hackcpp.sh --- cpp -P -D__HUGS__ $1 --- snap hackcpp.sh --- Here's what happens now: --- snip --- till@atlan:~/tmp> hugs -Fhackcpp.sh gammel.hs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-1999 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: February 2000 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Reading file "/usr/local/share/hugs/lib/Prelude.hs": Parsing/usr/local/share/hugs/lib/Prelude.hs:289:22: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:290:28: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:335:58: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:357:63: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:358:29: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:361:63: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:489:17: missing terminating ' character ERROR "/usr/local/share/hugs/lib/Prelude.hs" (line 207): Syntax error in expression (unexpected `=') FATAL ERROR: Unable to load prelude --- snap --- My question now is, whether there is a decent (and comfortable) way of dealing w/ this issue or whether I will have to preprocess the files myself manually? Thanks -- Till -- e-mail: reverse(net dot doerges at till) | ENCRYPTED | pgp/gpg: keys via keyserver or my homepage | MAIL IS | www: http://www.doerges.net | WELCOME! |
Hi,
to deal with issues such as this, here's what I normally do:
- for the ghc-only portions of my code, I wrap it up as follows
{- BEGIN_GHC_ONLY
....
END_GHC_ONLY -}
- for the Hugs-only portions, I similarly wrap these up
{- BEGIN_HUGS_ONLY -}
....
{- END_HUGS_ONLY -}
This will now work as expected with Hugs, with the GHC-only
block being treated as a comment. For GHC, you can get the
reverse behaviour by feeding it the following command-line options
-cpp -DBEGIN_GHC_ONLY='-}' -DEND_GHC_ONLY='{-'
-DBEGIN_HUGS_ONLY='{-' -DEND_HUGS_ONLY='-}'
i.e., nested comments to the rescue.
hth
--sigbjorn
btw, hugs & cpp - you also need to feed GNU cpp the -traditional
option (or -traditional-cpp) to turn off ANSI / ISO C features that
interacts badly with Haskell source code (tri-graphs, string and char
literal interpretations etc.)
----- Original Message -----
From: "Till Doerges"
Hi there,
hugs and ghc understand much the same, but a few (often subtle) differences remain. Since I'd be interested in developing code for both, I'm looking for a way to directly take care of these differences in my code.
Ghc offers a commandline option '-cpp' which will allow for '#ifdef' and other preprocessor directives. When testing it, it worked ok.
Hugs seems to offer a similar feature '-F<cmd>'. When testing it, however, it did not work. 'cpp' seems to be called, but it seems to leave characters in the code that can't be dealt w/ by hugs. Moreover, it seems to called on every input file (i.e. the prelude).
--- snip --- till@atlan:~/tmp> hugs -Fcpp gammel.hs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-1999 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: February 2000 _________________________________________
Haskell 98 mode: Restart with command line option -98 to enable extensions
Reading file "/usr/local/share/hugs/lib/Prelude.hs": Parsing ERROR "/usr/local/share/hugs/lib/Prelude.hs" (line 1): Syntax error in input (unexpected symbol "#")
FATAL ERROR: Unable to load prelude --- snap ---
When trying to remove the '#' etc. left in the code by giving '-P' to cpp it still doesn't work.
--- snip hackcpp.sh --- cpp -P -D__HUGS__ $1 --- snap hackcpp.sh ---
Here's what happens now:
--- snip --- till@atlan:~/tmp> hugs -Fhackcpp.sh gammel.hs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-1999 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: February 2000 _________________________________________
Haskell 98 mode: Restart with command line option -98 to enable extensions
Reading file "/usr/local/share/hugs/lib/Prelude.hs": Parsing/usr/local/share/hugs/lib/Prelude.hs:289:22: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:290:28: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:335:58: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:357:63: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:358:29: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:361:63: missing terminating ' character /usr/local/share/hugs/lib/Prelude.hs:489:17: missing terminating ' character
ERROR "/usr/local/share/hugs/lib/Prelude.hs" (line 207): Syntax error in expression (unexpected `=')
FATAL ERROR: Unable to load prelude --- snap ---
My question now is, whether there is a decent (and comfortable) way of dealing w/ this issue or whether I will have to preprocess the files myself manually?
Thanks -- Till -- e-mail: reverse(net dot doerges at till) | ENCRYPTED | pgp/gpg: keys via keyserver or my homepage | MAIL IS | www: http://www.doerges.net | WELCOME! |
_______________________________________________ Hugs-Users mailing list Hugs-Users@haskell.org http://www.haskell.org/mailman/listinfo/hugs-users
Another approach is to use the script included in hugs98/Install (attached). I'd use Sigbjorn's approach for simple config cases and only use this if things get complicated (different versions, etc.) Also, keep us informed about incompatabilities. We've been trying to fix as many as possible for the next release but we might have missed some. -- Alastair Reid --with-preprocessor This is an experimental feature and may change in future versions. Enable the use of a preprocessor for processing Haskell source files before compiling them with Hugs. When configured with preprocessing on, you can use the "-F" option to specify which preprocessor to use. For example, if your preprocessor is in /users/JFH/bin/hscpp, you might say :set -F"/users/JFH/bin/hscpp" If you have perl and gcc installed on your machine, the following script provides a simple cpp-like preprocessor. eval "exec perl -S $0 $*" if $running_under_some_random_shell; # # Reads CPP output and turns #line things into appropriate Haskell # pragmas. This program is derived from the "hscpp" script # distributed with the Glasgow Haskell Compiler. # $Cpp = 'gcc -E -xc -traditional'; open(INPIPE, "$Cpp @ARGV |") || die "Can't open C pre-processor pipe\n"; while (<INPIPE>) { # line directives come in flavo[u]rs: # s/^#\s*line\s+\d+$/\{\-# LINE \-\}/; IGNORE THIS ONE FOR NOW s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \2 \-\}/; s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \2 \-\}/; print $_; } close(INPIPE) || exit(1); # exit is so we reflect any errors. exit(0); Note that Hugs currently ignores the {-# LINE _ _ #-} pragmas so error messages will refer to the wrong line numbers.
On Fri, Nov 16, 2001 at 11:52:41AM -0700, Alastair David Reid wrote:
Another approach is to use the script included in hugs98/Install (attached).
Thanks.
Also, keep us informed about incompatabilities. We've been trying to fix as many as possible for the next release but we might have missed some.
Hugs provides a Show Instance for the IO-Types. Ghc doesn't. Bye -- Till -- e-mail: reverse(net dot doerges at till) | ENCRYPTED | pgp/gpg: keys via keyserver or my homepage | MAIL IS | www: http://www.doerges.net | WELCOME! |
participants (3)
-
Alastair David Reid -
Sigbjorn Finne -
Till Doerges