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

Alberto G. Corona agocorona at gmail.com
Thu Nov 11 03:57:12 EST 2010


There are some straighforward tricks using the package eval (or hint)l.

This is more or less the idea in pseudocode:

type FuncExpr= String

data F a = F FuncExpr a

apply (F _ f) x= f x

instance Show (F a) where show (F str _)= str

instance Read (F a) where read (F str f)= eval f >>= F str



2010/11/11 Jesse Schalken <jesseschalken at gmail.com>

> Is it possible to serialize and deserialize a function to/from binary form,
> perhaps using Data.Binary, for example? What about an IO action? If so, is
> there a way the serialized representation could be architecture-independent?
>
> I have been shown how useful it can be to store functions inside data
> structures, and while looking at data serialization for the purpose of
> persistence I wondered "since functions are just values in Haskell, why
> can't we persist them, too?".
>
> To me the idea has interesting implications. For example, an arbitrary
> program could simply be represented by a serialization of `IO ()`. In fact,
> you could load any program into memory from a file and use
> Control.Concurrent.forkIO to run it, and later kill it, giving you the
> beginnings of an operating environment. If such a serialization
> is architecture independent then to my understanding you have the beginnings
> of a virtual machine. You could break your program into pieces and store
> them in a database and load them when needed, or even pull updates to each
> piece individually from down the web etc, enabling interesting methods of
> software distribution. It would make very cool stuff possible.
>
> I have had a look at hs-plugins, but it is unclear how to derive a simple
> pair of functions `(a -> b) -> ByteString` and `ByteString -> Either
> ParseError (a -> b)`, for example, from the functionality it provides, if it
> is possible at all. I guess such a thing requires thorough digging into the
> depths of GHC, (or maybe even LLVM if
> an architecture independent representation is sought, but I don't know
> enough to say.). Perhaps this is more a question for those interested and
> knowledgable in Haskell compilation (and, to some extent, decompilation).
>
> If not Haskell, are there any languages which provide a simple
> serialization and deserialization of functions?
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101111/356d8ac0/attachment.html


More information about the Haskell-Cafe mailing list