Allocation & Marshalling Question

Adrian Hey ahey at iee.org
Mon May 12 11:37:55 EDT 2003


On Sunday 11 May 2003 19:01, Adrian Hey wrote:
> Playing about with this idea I came up with a definition of <+
> to work with FFI functions as they currently are:
>
>  infixl 0 <+
>  (<+) :: (Ptr a -> b) -> ((Ptr a -> IO b) -> IO b) -> b
>  f <+ alloc = unsafePerformIO $ alloc $ \p -> return $ f p
>
> Eeek! This actually seems to work on the examples I tried, though
> to be honest I have a very hard time imagining what's really
> going on at runtime with expressions using <+. Is it likely
> to be safe? and efficient?

Hmm, having thought about this I'm inclined to think this really
must be unsafe in general and if it appears to work that's just
good luck, not good design.

This seems a bit like the problem of how to implement C's printf
in Haskell, so maybe I should be looking at a similar solution
as those pointed out to me recently. What a pity I've forgotten
the reference :-( I think I'll stick with the nested lambdas after
all (must try to give my poor old brain a rest :-).

Regards
--
Adrian Hey    



More information about the FFI mailing list