The task here is as follows :
- The client requests a function to be executed providing a name and it's arguments.
- The server executes the function with the provided arguments and returns the result.
Something like this is fairly easy to implement in a dynamic typed language like Python. But, given Haskell's static typing, this seems increasingly difficult.
Here is my initial stab at the problem :
Assume that the functions in the module only take arguments which are serializable. Implement a
Serializable
type class (idea taken from Cloud Haskell).Store the functions in a map keyed using the function name. Doesn't work. The values of the map (function objects) need not be of same type.
The only thing I could come up with is to parse the module and generate a chain of
if else
statements (or acase
statement) invoking the right function based on the input string and then serializing the result.This gives a pathetic performance as the worst case 'lookup' time of a function will be dependent on the number of functions in the module.
What is the right way to approach this problem? Is there something trivial that I'm missing here?