[Haskell-cafe] How do you make constant expressions?

Daniel Fischer daniel.is.fischer at web.de
Sun Jul 18 16:26:09 EDT 2010


On Sunday 18 July 2010 22:19:21, Eitan Goldshtrom wrote:
> Silly question, but I can't find the answer on the net. I think I'm just
> using the wrong words in my search. I'm looking for a way to create
> constant expressions in Haskell. The C/C++ equivalent of what I'm
> talking about is
>
> #define NAME VALUE
>
> I want an expression, or really just numbers for what I'm doing, that
> the compiler will put into the program at the designated places, instead
> of storing it in memory like a variable.
>
> -Eitan

Just make a top-level definition

name = value

and if you want to make sure it's inlined,

{-# INLINE name #-}

Or you can use {-# LANGUAGE CPP #-} with the #define


More information about the Haskell-Cafe mailing list