some messy unsafePerformIO usage
I wanted to parse some data using Aeson, with the caveat that additional, uninspected keys were not welcome and should result in an error being thrown.
Aeson doesn't seem to come with a mechanism to do this, so I made my own. I add new lookup operators that register the requested key, so that later on I can detect if there are more keys in the object than were inspected.
I didn't really want the hassle of a monad transformer (add a huge amount of
lifts to the parsing code), so I used an IORef. When I compiled the code, I ran into the issue that
usafePerformIO $ newIORef ... would be cached, so only one IORef would ever get created. So I had to manually sequence pure and impure operations, and for this i created
This is… Horrible, right?
Is there a nicer way, that doesn't involve a monad transformer ie
StateT (Set Text) Parser a?
Submitted July 16, 2017 at 07:30PM by libscott
via reddit http://ift.tt/2t7SPJz