On Fri, Oct 17, 2003 at 01:38:06PM +0100, Alastair Reid wrote:
The simplest would be to generate some C code at runtime, pass it to gcc and dynamically load the resulting .o file. yeah, I considered this but want to implement an interpreter where the user has the ability to call arbitrary C functions, A C compiler can't be guarenteed to exist.
1) It's going to be challenging to use the resulting Haskell functions because Haskell's typechecker won't know their type at runtime. You'll probably need to use something like the Dynamic library's runtime typechecking. yeah, thinking about it the type I gave to callFunPtr is all wrong. something involving Dynamic or existential types will probably have to be used.
Okay, this seems like it will be much trickier than I expected, so I am thinking of the following 'hack' generate every foreign dynamic import for all types of functions with less than say 5 arguments (I can probably prune this due to argument promotion rules) then just call the appropriate mkFun on the function pointer based on the types I want to pass to it. does this seem plausable? I am not quite sure how I would chose the appropriate dynamic import when they all have different types, in any case I will probably not want to write this by hand.. is there any big overhead in attaching a ton of forign import dynamic statements to a program? John -- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@foo.net ---------------------------------------------------------------------------