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

Simon Marlow simonmar at microsoft.com
Mon May 23 06:31:20 EDT 2005


Yes, I think that sentence in the awkward squad paper is incorrect.  The
"unsafe" annotation on foreign import is not related to the purity of
the function being called, it is the omission of 'IO' on the return type
that indicates intended purity.

Cheers,
	Simon

On 19 May 2005 16:39, Bulat Ziganshin wrote:

> Hello Peter,
> 
> Sunday, May 15, 2005, 4:07:28 PM, you wrote:
> 
>>   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



More information about the Glasgow-haskell-users mailing list