[Haskell-beginners] Haskell Preprocessor?

Daniel Fischer daniel.is.fischer at web.de
Wed Sep 24 22:07:49 EDT 2008


Am Donnerstag, 25. September 2008 03:57 schrieb Mike Sullivan:
> Hi All,
>
> What is the easiest and/or best way to define global "constants" in Haskell
> (avoiding any side effects, of course). The functionality I'm thinking of
> is similar to the use of global "const" variables or #defines in C code.

If you don't use side effects, just have a top-level name

taxiCabNumber :: Integer
taxiCabNumber = 1729

otherConstant :: [Double]
otherConstant = result of some computation
-- which only is executed once per run of programme if at all

Why would you need a preprocessor for that?

>
> Judging from this article (
> http://www.lochan.org/keith/publications/hspp-hw99.ps.gz) and the existence
> of the GHC -cpp command-line option, it seems that it is possible to use
> the C preprocessor on Haskell code. However, the article is fairly old
> ('99)... Is this still (or was it ever) the best way? The point of the
> article is that it's not... were any of the "Haskell preprocessor"
> suggestions in the paper (dubbed "HsPP") adopted by GHC, and can we use
> them?
>
> There also seems to be a (almost fully) native implementation of a Haskell
> preprocessor in Hackage (
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cpphs). Does
> anybody use it?
>
> What would you use if you wanted such functionality?
>
> Thanks!
> Mike



More information about the Beginners mailing list