visq / language-c

Source repository for https://hackage.haskell.org/package/language-c
http://visq.github.io/language-c/
Other
87 stars 45 forks source link

[Analysis] Trav ought to be a monad transformer #53

Open lambdageek opened 6 years ago

lambdageek commented 6 years ago

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..

aweinstock314 commented 5 years ago

I ended up needing a MonadIO instance, so I wrote https://github.com/visq/language-c/pull/59.

expipiplus1 commented 4 years ago

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.