[Haskell-cafe] Re: Code that writes code
waldmann at imn.htwk-leipzig.de
Fri Aug 20 07:27:22 EDT 2010
Graham Klyne <GK <at> ninebynine.org> writes:
> [...] rather than go through the step of
> generating source code and feeding it back into a Haskell compiler, it may be
> possible to use higher order functions to directly assemble the required logic
> within a single program. For me, this is one of the great power-features of
> functional programming [...]
I agree one-hundred-percently, and that's also what I stress when I teach.
But of course this has to be balanced with the observation
that in current Haskell, not everything is a value.
Functions are, but modules and types are not.
That's why you cannot directly handle them programmatically.
So you either rewrite the program (unify the "similar" modules/types)
or resort to syntactic manipulation (as a compiler pass - like template haskell,
or by external processors) which has the severe downside
of losing static typechecking (even if the generator is type-checked,
you cannot be sure that its output is type-safe).
Anyway the original poster asked about cabal integration.
For that, code generation in the compiler (template haskell)
certainly is easier than external processors.
The gtk2hs project also needs to generate boilerplate,
and they put their generators into a separate package
that you need to cabal-install before.
(somewhat strangely, gtk2hs-buildtools is not a dependency of gtk?
Is that because cabal packages cannot depend on executables?)
More information about the Haskell-Cafe