[Haskell-cafe] The amount of CPP we have to use is getting out of hand

Ben Gamari ben at smart-cactus.org
Fri Jan 9 23:48:03 UTC 2015


Nicola Gigante <nicola.gigante at gmail.com> writes:

>> Il giorno 09/gen/2015, alle ore 14:55, Johan Tibell <johan.tibell at gmail.com> ha scritto:
>> 
>> Hi,
>> 
>> (This was initially written as a Google+ post, but I'm reposting it
>> here to raise awareness of the issue.)
>> 
>> The amount of CPP we have to use in Haskell is getting a bit out of
>> hand. Here are the number of modules, per library, that use CPP for
>> some of the libraries I maintain:
>> 
[snip]

> Hi
>
> I’m an outsider so this could probably sound ingenuous but,
> why not thinking about an in-language feature to solve the
> problems addressed by CPP?
>
This might be a good time to bring in the data point provided by
Rust [1], where the attribute system to allow conditional
compilation. For instance,

    #[cfg(not(a_feature))]
    pub fn my_function() { ... }

    #[cfg(a_feature)]
    pub fn my_function() { ... }

The build system can then detect whether the feature in question is
available, and potentially pass `-f a_feature` to the compiler.  `cfg`
items can also have string values which can be tested for equality
(although I think they intend on extending this at some point).

This works well for them as it is flexible and fits nicely into the
language, reusing the attribute syntax that Rust users are already
familiar with.

The closest thing Haskell has to this is the conventional `{-# ... #-}`
pragma syntax, but leveraging this would almost certainly require
compiler support and a language extension.

Cheers,

- Ben


[1] http://doc.rust-lang.org/reference.html#conditional-compilation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150109/eb8c7301/attachment.sig>


More information about the Haskell-Cafe mailing list