error in your article? about meaning of safe/unsafe in "foreign import"

Bulat Ziganshin bulatz at HotPOP.com
Thu May 19 11:38:51 EDT 2005


Hello Peter,

Sunday, May 15, 2005, 4:07:28 PM, you wrote:

PS>   http://research.microsoft.com/Users/simonpj/papers/marktoberdorf/

this article says that

--------------------------------------------------
some foreign procedures may cover have purely­functional semantics. For example,
the C sin function really is a function: it has no side effects. In this
case it is extremely tiresome to force it to be in the IO monad. So the Haskell FFI
allows one to use the unsafe keyword, and omit the ``IO'' from the return type, thus:

 foreign import ccall unsafe sin :: Float ­> Float
 
As in the case of unsafePerformIO (Section 2.6), ``unsafe'' indicates that the programmer
takes on a proof obligation, in this case that foreign procedure is genuinely functional.
--------------------------------------------------



while the FFI specification state that

--------------------------------------------------
Optionally, an import declaration can specify, after the calling convention, the safety level that
should be used when invoking an external entity. A safe call is less efficient, but guarantees to
leave the Haskell system in a state that allows callbacks from the external code. In contrast, an
unsafe call, while carrying less overhead, must not trigger a callback into the Haskell system. If
it does, the system behaviour is undefined. The default for an invocation is to be safe. Note that
a callback into the Haskell system implies that a garbage collection might be triggered after an
external entity was called, but before this call returns. Consequently, objects other than stable
pointers (cf. Section 5.6) may be moved or garbage collected by the storage manager.
--------------------------------------------------


and one more question: is it possible to download sources of http
server mentioned in this article? i want to browse the code, it's no
matter how it compiles and works

-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Glasgow-haskell-users mailing list