
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. 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

On 2008 Sep 24, at 21:57, Mike Sullivan wrote:
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.
ghc at least *should* be smart enough to take a = 5 and optimize all uses of "a" away via inlining, giving you a constant declarator. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

A simple question deserves a simple answer, I suppose.
My brain must still be in the imperative language namespace. Thanks,
everybody.
Mike
On Wed, Sep 24, 2008 at 9:06 PM, Rahul Kapoor
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.
Why not a simple definition:
somename = 1
Cheers, Rahul

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
participants (4)
-
Brandon S. Allbery KF8NH
-
Daniel Fischer
-
Mike Sullivan
-
Rahul Kapoor