Does DAML have any sort of preprocessor

In Danban I used a pattern where every module was versioned using V1, V2, etc. tags. Bumping the version needed changes in a lot of places. It would be much nicer to solve this with a preprocessor, which would allow me to just put VER everywhere and substituted the appropriate value. Similarly in the upgrade contracts, it would be nice to just be able to specify FROM_VER and TO_VER and have a preprocessor do its magic.

I take it GHC’s CPP doesn’t work as I get the error

damlc: ghcversion.h missing;

Is there any other way?

1 Like

In principle, Haskell’s CPP can be made to work with DAML and we do use that in the DAML standard libraryy to make it depend on the LF target version. However, this is currently not exposed in the version shipped in the SDK and you’ll have to jump through a lot of hoops to make it work.

You could just run CPP over the files yourself before calling daml build but you’ll have to direct the output to a bunch of temp files and it all gets rather ugly.

For upgrading specifically, I don’t really understand how a preprocessor helps much. You rarely do whole-package upgrades so you have to interact with different versions and cannot just treat the version as a placeholder.

I Danban I did actually always do whole version upgrades. I simply had packages V1, V2, V3, … that each contained the entire application, and upgrade packages to upgrade from VN to VN+1. CPP would have added some value there, though probably not enough if it’s difficult to get running,