[Haskell-cafe] A restricted subset of CPP included in a revisionof Haskell 98

Brian Hulley brianh at metamilk.com
Thu Aug 17 17:11:31 EDT 2006

On Thursday, August 17, 2006 7:54 PM, Brian Smith  wrote:

> I want to have conditionals limited in their placement
> to make things easier for refactoring tools. But, I
> don't have any ideas about how to deal with
> conditional exports without allowing preprocessor
> conditionals in the export list.

It seems to me that all uses of the preprocessor could be avoided except for 
cases like:

    #ifdef _SPARC
            -- sparc code
        #ifdef _INTEL86
            -- i86 code
            -- byte code

and the above could afaics be dealt with by having a conditional import 
directive eg:

    module Platforms (Platform(..)) where
        data Platform = Sparc | Intel | ByteCode

    module Client where
        import Platform

        import qualified (

                case #Platform of
                        Sparc -> Compiler.Sparc.CodeGen
                        Intel -> Compiler.Intel.CodeGen
                        _ -> Compiler.ByteCode.CodeGen

                ) as CodeGen

where a leading '#' denotes a preprocessor symbol (corresponding to the type 
of the same name) which can only be set outside the program ie on the 
command line, thus ensuring that the same module can't have multiple 
interpretations in the same program.

Conditions could be formed using case, if, and expressions which can be 
evaluated at compile time.

Of course this would require some effort to modify existing code, but it 
would have the great advantage that the conditional compilation would be 
well typed and be part of the normal grammar thus making it easier to write 
refactoring tools.

Regards, (another) Brian.
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

More information about the Haskell-Cafe mailing list