The encoding package uses HaXml in its build script (in Setup.hs). It happens to use bits of the interface that changed between HaXml-1.19 and HaXml-1.22. It would be nice if the encoding package were able to build with either version. I tried using the usual Cabal trick, namely, doing something like
{-# LANGUAGE CPP #-}
#if MIN_VERSION_HaXml(1,22,0)
-- HaXml-1.22 code
#else
-- HaXml-1.19 code
#endif
…but the magic defines can’t exist before the package is configured, and this file is being built to make the configure step possible. What are my options? Is there a way to change the command that cabal-install calls to compile Setup.hs? Is there another mechanism for conditionally selecting code that sidesteps cabal?
The
Data.Datainterface is capable (just about!) of constructing and deconstructing values of a type that may or may not exist. Unfortunately, HaXml doesn’t appear to haveDatainstances for its types, and you can’t define one since you can’t refer to the type that might or might not exist, so we have to resort to Template Haskell:The following module exports
qnameCompat:When spliced at the top level using Template Haskell,
qnameCompatwill check ifNexists. If it does, it produces the following code:If it doesn’t, the following is produced:
Now you can create and deconstruct
Elements, e.g. using the ViewPatterns extension:ViewPatterns is convenient, but not essential, of course: using ordinary pattern matching on the result of
fromQNamewill work just as well.(These ideas are what led me to develop the notcpp package, which includes
maybeReifyand some other useful utilities)