Extract values ​​environment from Q monad

In Template Haskell, the monad Q

is where all the magic happens. However, it Q

has a rather limited API. I would like to have a type value valueNameStore :: Q (String -> Maybe Name)

that basically captures the functionality lookupValueName :: String -> Q (Maybe Name)

, but with the stock of variables currently available, it is bound.

I think this sounds in theory: I don't need to order my searches if I execute them against the general state of the constant, which is a snapshot of the state Q

when I originally called bind on valueNameStore

.


If this is not possible, is there any way to banish it in an unsafe way? I'm ready to dive down to any hacks related to unsafePerformIO

...

+3


source to share


1 answer


The answer is basically no. There might be a flawed way to do this, if you can list the names in the scope in some way. While you are correct that the operation on the type and semantics you propose is perfectly reasonable, this does not mean that it is (intelligently) implemented from the provided interface even with unsafePerformIO

.



Basically, the display of strings in Name

is mutable. What you want to do requires a snapshot of this mutable dictionary. The API does not provide that functionality, and as far as I can tell, it also does not provide you with the tools to manually copy the data yourself. Trying to use unsafePerformIO

will result in you getting all the bindings in the mapping while evaluating the expression, which, if you change the scope, will be different from the ones you called on action Q

.

0


source







All Articles