
On Thu, Nov 11, 2010 at 12:53 AM, Jesse Schalken
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?
As far as I know, GHC has no support for this. There are issues with the idea that will come out pretty fast, such as: (1) Those cannot be pure functions, because it differentiate denotationally equal functions. So it would have to be at least (a -> b) -> IO ByteString. (2) What if you tried to serialize a filehandle or an FFI Ptr? But my answers are "Ok" and "Then you get a runtime error", respectively. It is by no means impossible, IIRC Clean does it. I think it's pretty dumb that we don't have support for this yet. Purely functional languages have a unique disposition to be very good at this. But oh well, there aren't enough tuits for everything. A more elaborate answer to (2) is "you get a runtime error when you try to *use* the thing that was impossible to serialize". This makes sure that you don't get an error if you are trying to serialize \x -> const x a_filehandle_or_something, which is just the identity function. Luke