
Andrew Coppin wrote:
In other words, you can store a value (of arbitrary type) under a unique key. The monad chooses what key for you, and tells you the key so you can look up or alter the value again later. Under the covers, it uses Data.Map to store stuff. I used some trickery with existential quantification and unsafeCoerce (!!) to make it work. Notice the sneaky phantom type in the key, telling the type system what type to coerce the value back to when you read it. Neat, eh?
I did exactly that in my Yogurt project[1]. It felt dirty but in a good way, mostly because the interface was exactly what I needed. :-)
...until I realised that somebody that somebody could generate a key in one run and then try to use it in another run. o_O
I've worried about this but I couldn't find a good code example of when this goes wrong. Can you? Without using any of the unsafeXxx functions, of course. Maybe I should build my monad on top of the ST monad if that makes things safer. Martijn. [1] http://hackage.haskell.org/packages/archive/Yogurt/0.2/doc/html/Network-Yogu...