home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / hugs_1 / !Hugs_libhugs_ST < prev    next >
Encoding:
Text File  |  1996-08-12  |  1.2 KB  |  33 lines

  1. -----------------------------------------------------------------------------
  2. -- Lazy state threads:
  3. --
  4. -- This file contains (non-standard) hooks for an implementation of
  5. -- the lazy state thread monad, ST, as described in the PLDI '94
  6. -- paper by John Launchbury and Simon Peyton Jones.
  7. --
  8. -- These operations are only available if the version of Hugs that you
  9. -- are using was built with the LAZY_ST flag set.
  10. --
  11. -- Suitable for use with Hugs 1.3.
  12. -----------------------------------------------------------------------------
  13.  
  14. module ST where
  15.  
  16. data MutVar s a     -- implemented as an internal primitive
  17.  
  18. primitive returnST     "STReturn"   :: a -> ST s a
  19. primitive thenST       "STBind"     :: ST s a -> (a -> ST s b) -> ST s b
  20. primitive newVar       "STNew"      :: a -> ST s (MutVar s a)
  21. primitive readVar      "STDeref"    :: MutVar s a -> ST s a
  22. primitive writeVar     "STAssign"   :: MutVar s a -> a -> ST s ()
  23. primitive mutvarEq     "STMutVarEq" :: MutVar s a -> MutVar s a -> Bool
  24. primitive interleaveST "STInter"    :: ST s a -> ST s a
  25.  
  26. instance Eq (MutVar s a) where (==) = mutvarEq
  27.  
  28. instance Monad (ST s) where
  29.     return = returnST
  30.     (>>=)  = thenST
  31.  
  32. -----------------------------------------------------------------------------
  33.