Allocation & Marshalling Question (again)

Adrian Hey ahey at iee.org
Thu May 29 10:28:21 EDT 2003


On Thursday 29 May 2003 11:18, Adrian Hey wrote:
> I don't see any significant difference between proper
> treatment of pointers and proper treatment of IORefs. For example
> functions of type..
> 	IORef a -> [IORef a] -> [IORef a]
> are perfectly ok, despite the fact that they can't do anything
> (I.E read or write) with their IORefs.

Whoops, now I see a real problem with what I'm asking for.

I guess since the (hypothetical) withCString is creating
a new CString (bit like an IORef) it should have type

  withCString :: String -> (CString -> b) -> IO b

and I guess my <+ should be..
  (<+) :: (a -> b) -> ((a -> IO b) -> IO b) -> IO b
  f <+ alloc = alloc $ \p -> return $ f p

(Well at least that's got rid of the unsafePerformIO :-)

Would this be safe?

Regards
--
Adrian Hey	



More information about the FFI mailing list