RE: difference between (evaluate . runST) and stToIO

2002-08-28 Thread Simon Peyton-Jones

They aren't identical.  

runST guarantees to run a complete state thread that can't interact
with any other.  stToIO runs some imperative actions that might 
interact with other stToIO calls.

You might find it helpful to read 'State in Haskell' if you havn't
already done so.

Simon

| -Original Message-
| From: Hal Daume III [mailto:[EMAIL PROTECTED]] 
| Sent: 06 August 2002 18:55
| To: Haskell Mailing List
| Subject: difference between (evaluate . runST) and stToIO
| 
| 
| I can't seem to figure out what the difference is between using
| 
|   evaluate (runST action)
| 
| and
| 
|   stToIO action
| 
| when in the IO monad and running something in ST...they seem 
| to behave identically...are they?
| 
| If they are, why do they have different type signatures (one 
| is ST RealWorld a - IO a, while the other is (forall s. ST s 
| a) - IO a)?
| 
|  - Hal
| 
| --
| Hal Daume III
| 
|  Computer science is no more about computers| [EMAIL PROTECTED]
|   than astronomy is about telescopes. -Dijkstra | www.isi.edu/~hdaume
| 
| ___
| Haskell mailing list
| [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
| 
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



RE: difference between (evaluate . runST) and stToIO

2002-08-13 Thread Simon Marlow

 I can't seem to figure out what the difference is between using
 
   evaluate (runST action)
 
 and
 
   stToIO action
 
 when in the IO monad and running something in ST...they seem to behave
 identically...are they?
 
 If they are, why do they have different type signatures (one is ST
 RealWorld a - IO a, while the other is (forall s. ST s a) - IO a)?

With stToIO, you can do this:

   do r - stToIO newSTRef
  stToIO $ writeSTRef r 42
  ...

the types prevent you doing that with runST, but runST is safe to use in
pure code whereas stToIO must be used in the IO monad.

Cheers,
Simon
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell