[Haskell-cafe] Serialization of (a -> b) and IO a

C. McCann cam at uptoisomorphism.net
Thu Nov 11 15:07:29 EST 2010

On Thu, Nov 11, 2010 at 1:57 PM, Stephen Tetley
<stephen.tetley at gmail.com> wrote:
> On 11 November 2010 18:01, C. McCann <cam at uptoisomorphism.net> wrote:
>> For instance, assuming serialize can be applied to functions of any
>> type, it would probably be trivial to write a function (isExpr :: a ->
>> Bool) that reports whether an arbitrary term is a primitive value or
>> the result of some expression [SNIP]
> Persistent functional languages usually give serialized values
> including closures a dynamic type. So can you write isExpr :: Dynamic
> -> Bool ?

But it's not the type of the serialized value that's at issue, it's
the type of the serializable values. Anything that lets you convert an
arbitrary closure into something with internals open to inspection
will likely have dire consequences for parametricity and referential
transparency. Remember, the problem isn't what you do with the
serialized form itself, it's what you can learn via it about the
original value it was serialized from. To retain sanity, either "types
that can be serialized" must be marked explicitly (perhaps in the
context, similar to having a Data.Typeable constraint) to indicate
potential non-parametric shenanigans, or the result of serializing and
inspecting a value must be quarantined off, such as with IO. Or some
other mechanism, but those seem like the obvious choices.

Having a full serialization function without some restriction along
those lines would be like renaming unsafePerformIO to runIO, moving it
to Control.Monad.IO, and telling people "hey, just don't misuse this
and everything will be okay".

- C.

More information about the Haskell-Cafe mailing list