[Haskell-cafe] Code that writes code

Andrew Coppin andrewcoppin at btinternet.com
Fri Aug 20 14:21:04 EDT 2010


Graham Klyne wrote:
> Maybe not helpful to you at this stage, but...
>
> An alternative to generating source code is to factor out the common 
> "boilerplate" elements into separate functions, suitably 
> parameterized, and to use higher order functions to stitch these 
> together.

Well, yeah, if you've got so much boiler plate that you have to automate 
generating the boilerplate, you're probably doing it wrong. ;-)

All I'm actually using it to do is generate a set of fixed-size 
containers (each of which has a bazillion class instances). I've got a 
variable-sized container, but sometimes it's useful to statically 
guarantee that a container is a specific size. In addition, by being 
fixed-size you can get a few small performance gains. That's really all 
I'm using autogeneration for.

I suppose instead of building an ADT for each container size, I could 
just write a newtype over the variable-size container and put a phantom 
type on it representing the size... That would give me the static 
guarantees but not the efficiency.



More information about the Haskell-Cafe mailing list