[jhc] Monad.ST

Henning Thielemann jhc at henning-thielemann.de
Sat Nov 14 18:38:33 EST 2009


Before looking into the actual source code of the ST monad, I thought that 
ST must be something like

   newtype ST s a = ST (IO a)

where the strict ST monad is based on normal IO bind function and lazy ST 
monad also uses unsafeInterleaveIO. Then runST would be just an 
unsafePerformIO.

However when looking into
   http://darcs.haskell.org/packages/st

  it is in Control.Monad.ST.Lazy
    newtype ST s a = ST (State s -> (a, State s))
    data State s = S# (State# s)

  and in Hugs.ST:
    newtype ST s a = ST (forall r. (a -> r) -> r)

Both GHC and Hugs seem to use primitives, that are not available in JHC. 
Would my IO definition above be correct, at all? It seems that much of the 
code in the 'st' package could not be re-used in JHC.


More information about the jhc mailing list