RE: unsafePtrCompare, anybody?

2001-09-18 Thread Simon Marlow


 One's intuition would suggest that you could be safely 
 implement mkAtom 
 without wrapping it in a IO monad.   After all, at least at a 
 abstract level, 
 an atom table is referentially transparent.  The library 
 documentation says 
 that lack of side effects and environmental independance is 
 sufficent to 
 order for uses of unsafePerformIO to be safe.  Is there a 
 exact (or at least 
 better) criterion for safety?   

An exact criterion would require a formal semantics for Haskell, which
we don't have.  But informally, if a function which is implemented using
unsafePerformIO is pure - that is, its result depends only on the values
of its arguments and possibly its free variables - then that is a safe
use of unsafePerformIO.

 unsafePerformIO is used in the implementation of 
 mkFastString, so how is it's side effects safe.

It is safe because the side effects aren't visible outside the
implementation of mkFastString.

HTH,
Simon

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: unsafePtrCompare, anybody?

2001-09-18 Thread Alastair David Reid


Leon Smith [EMAIL PROTECTED] writes:
 My intuition says that none of the side-effects in my implementation
 are visible from the abstract level of the module.  However, the use
 of unsafePerformIO certainly modifies the behaviour of the module.

Here's a simple test you can apply:

  Can you rewrite your module in pure Haskell so that it has the
  same observed behaviour but (probably) different operational
  behaviour (e.g. space and time usage)?

If the answer is yes, then you preserve referential transparency, type
safety and other desirable properties (on the assumption that pure
Haskell has these properties).

If the answer is no, you've probably broken one or more important
properties.  (There may still be hope but you might have to get very
devious (cf. non-determinism in Rittri et al.'s UniqueSupply, Hughes
and O'Donnell's non-determism monad and exception handling).)

-- 
Alastair Reid[EMAIL PROTECTED]http://www.cs.utah.edu/~reid/

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users