Allow template-haskell to communicate with itself between compilation units through the interface file
I'd like to be able to have something like this in the Q monad:
type MessageName = String -- or something better, I don't know writeIface :: (Quasi q, Serializable a) => MessageName -> a -> q () readIfaces :: (Quasi q, Serializable a) => MessageName -> q [a]
Or instead of returning
[a], I'm of course fine with a
Monoid, I just need the gathered results for every occurrance of the MessageName.
This has to be in the interface file, because I'd like this to work through compilation units, like class instances, I'd like to get every result in the readIfaces call that is ever imported from the current module (transitive closure).
Please note, that in a very hacky way this is already possible to do by abusing classes. Namely, I create an empty class for my message type. When I want to send a message, I create a new empty datatype named for the message and I make this an instance of the class. Then on the receiving side I just have to reify the class and I will receive all my instance names/messages.
This came up while implementing the
Maybe I shouldn't be proud of this, but we currently do the hacky way explained above. I would love to have a clean approach.