
My question is: should I implement it through the FFI or as a primitive ala primops.txt? Perhaps they amount to much the same thing.
I'd make it a primop if there were some really unusual strictness issues involved or, if I wanted to eliminate all overhead, as in integer addition or if the operation did strange things to the state of the abstract machine (like pushing an exception-handler frame). I'd use the ffi for anything else. Here, there is a strange strictness issue (you don't want printObj to evaluat its argument) but SimonM's suggestion that you really want to use a stable pointer gets round this. What you'll need is a little wrapper function which will convert the stableptr into an StgClosure* void printObj_wrapper(StablePtr x) { printObj(derefStablePtr(x)); } (I'm sure the names of types and functions doesn't match those in header files - but hopefully the ones you want are easy to find.) -- Alastair Reid