language-c
language-c copied to clipboard
[Analysis] Trav ought to be a monad transformer
Here's a wishlist item I've been thinking about: I wish Trav was a monad transformer built up out of smaller simpler monad transformers.
Trav s a is meant to be extensible via the userState component s and the handleDecl function from MonadTrav, but this isn't always enough.
For example if I want to handle some events by running some kind of imperative operation (e.g. some kind of Union-Find algorithm or maybe feeding facts to an external solver like Z3) that's not easy to do right now.
Instead of baking in user state into the monad, Trav should be a monad transformer: TravT m a and Trav s a = TravT (State s) a (I'm not sure how user state interacts with Trav's exception mechanism).
In fact, ideally the MonadSymtab and MonadName, and MonadCError parts of Trav should all be broken out into separate transformers that layer on the functionality one by one (so that if I want to have some kind of extended symbol information, for example, I could add my own MonadSymtab instance in a custom stack). The default TravT should be a newtype around a particular instantiation of a stack of simpler transformers..
I ended up needing a MonadIO instance, so I wrote https://github.com/visq/language-c/pull/59.
Fixed partially in https://github.com/visq/language-c/pull/77
The user state is broken out into a MonadState instance, but not the other features.