[Haskell-cafe] Re: looking for origin of quote on preprocessors
and language design
Jason Dusek
jason.dusek at gmail.com
Thu Jan 14 12:14:55 EST 2010
2010/01/07 Maciej Piechotka <uzytkownik2 at gmail.com>:
> On Thu, 2010-01-07 at 13:32 +0100, Johannes Waldmann wrote:
> > Dear all,
> >
> > It's not exactly Haskell-specific, but ...
> > I am trying to track down the origin of the proverb
> >
> > "the existence (or: need for) a preprocessor
> > shows omissions in (the design of) a language."
> >
> > I like to think that in Haskell, we don't need
> > preprocessors since we can manipulate programs
> > programmatically, because they are data.
> >
> > In other words, a preprocessor realizes higher order
> > functions, and you only need this if your base language
> > is first-order.
> >
> > Yes, that's vastly simplified, and it does not cover
> > all cases, what about generic programming
> > (but this can be done via Data.Data)
> > and alex/happy (but we have parsec) etc etc.
>
> Not quite. While I agree that "the *frequent* need for a preprocessor
> shows omissions in (the design of) a language." it is not necessary the
> case. Preprocessor may be useful if:
>
> - there is a new beatyful feature in newer version of compiler but you
> still want to have backward compatibility.
> - there are compiler or platform dependant elements. For example if you
> write a driver in Haskell you may want to share code as much as possible
> but you need to know 1) the size of registers and 2) the platform you're
> writing as Windows have quite different API then Linux or BSD.
> - You need to enable/disable features at build-time. It is not frequent
> at closed-source system but it is frequent on OpenSource systems. For
> example I might need to have minimal program for embedded system but
> with full feature set it likly conquer the desktops
>
> in such cases it is easier/more efficient to just write
> #if (defined WINDOWS && BITS >= 64) || defined ALSA
> ...
> #elseif GHC_VERSION >= 061004
>
> #endif
I think that pre-processing is an inevitable result of poor
support for DSLs. When looking into embedded programming for
the AVR family recently, I was surprised at the degree to
which programmers rely on C macros; they're the only way they
can get the expressiveness they want at a price they can
accept.
Haskell has strong support for embedded DSLs and the
abstraction penalty is low so it's not hard to get away with
just writing Haskell for things. Just the same, there are some
aspects of Haskell syntax that make it horribly awkward for
some applications. I would like to write all my shell scripts
in Haskell -- especially those scripts that drive SSH
connections or multiple external processes -- but the line
noise penalty is pretty high right now. Using quasi-quotation
-- a kind of pre-processor -- with a more shell-like set of
shortcuts might be just the right thing.
It's nice to reflect on the fact that Haskell offers a lot of
flexibility for program transformation but is relatively safe
from the incomprehensibility that results from the use of
monkey patching in Ruby or macros in general.
--
Jason Dusek
More information about the Haskell-Cafe
mailing list