Re: [Haskell-cafe] Code that writes code

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.

Andrew Coppin wrote:
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.
Have a look at how hmatrix-static does this for linear algebra while sitting on top of hmatrix (both are on hackage). Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Have you looked at creating Template Haskell splices to generate this for you? On Friday Aug 20, 2010, at 2:21 PM, Andrew Coppin wrote:
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.

Bill Atkins wrote:
Have you looked at creating Template Haskell splices to generate this for you?
The thought had crossed my mind. On the other hand, with my current approach, the generated code is just another source file that doesn't look any different. On reflection, I kinda like that.
participants (3)
-
Andrew Coppin
-
Bill Atkins
-
Erik de Castro Lopo