Code for hugs and ghc

Sigbjorn Finne sof@galconn.com
Wed, 7 Nov 2001 08:00:15 -0800


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" <till@doerges.net>
To: <hugs-users@haskell.org>
Sent: Wednesday, November 07, 2001 03:19
Subject: Code for hugs and ghc


> 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