Hi all,
I've written a patch which I would like reviewed before pushing.
You can view the changes at [1]. The patch is a rewrite of the
Yi.Dynamic module to support serialisation on Dynamics (which means that
things like minibuffer history are preserved across 'reloadConfigE').
The module Yi.Dynamic contains the interesting changes; most other
changes are just the necessary instances of Binary for the modules which
were using Yi.Dynamic.
I'll briefly explain the new implementation. We might try to implement
serialisable dynamics as
data Dynamic = forall a. (Binary a, Typeable a) => Dynamic a
Serialisation is easy, but deserialisation is not: when we're
deserialising, all we can read in is the TypeRep and the serialised data
(a ByteString). How can we possibly find the correct 'Binary a' instance
from that?
So, we add another constructor:
data Dynamic = forall a. (Binary a, Typeable a) => Dynamic a
| Serial TypeRep ByteString
The trick is that we get the Binary instance when we read from the dynamic:
fromDynamic :: (Typeable a, Binary a) => Dynamic -> Maybe a
fromDynamic (Serial tr bs) = if<check the types> then Just (decode bs) else
Nothing
This is all good, except we run 'decode' every time we read from the
Dynamic.
I decided to avoid this unnecessary work by wrapping the Dynamic in an
IORef, and changing the representation from Serial to Dynamic once we
have run fromDynamic. Everything is then wrapped in unsafePerformIO, to
present a pure interface.
What do you think of this decision? The exported API is genuinely pure,
but the implementation is not.
Cheers,
Reiner
[1]
https://github.com/reinerp/yi/commit/087263a1d1d7374d3c7fc1195c0d322e488b36e1
--
Yi development mailing list
yi-devel@googlegroups.com
http://groups.google.com/group/yi-devel