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

  1. -----------------------------------------------------------------------------
  2. -- Mutable arrays for lazy state threads:
  3. --
  4. -- This file contains (non-standard) hooks for an implementation of
  5. -- mutable arrays for the lazy state thread monad, ST, in Hugs 1.3.
  6. -- These primitives are compatible with the ones described in the
  7. -- PLDI '94 paper by John Launchbury and Simon Peyton Jones.
  8. --
  9. -- These operations are only available if the version of Hugs that you
  10. -- are using was built with the LAZY_ST and HASKELL_ARRAYS flags set.
  11. --
  12. -- Suitable for use with Hugs 1.3.
  13. -----------------------------------------------------------------------------
  14.  
  15. module STArray where
  16.  
  17. import ST
  18. import Array
  19.  
  20. data MutArr s a b -- implemented as primitive
  21.  
  22. primitive primSTNewArr   "STNewArr"
  23.                   :: (a -> Int) -> (a,a) -> b -> ST s (MutArr s a b)
  24. primitive primSTReadArr  "STReadArr"
  25.                   :: ((a,a) -> a -> Int) -> MutArr s a b -> a -> ST s b
  26. primitive primSTWriteArr "STWriteArr"
  27.                   :: ((a,a) -> a -> Int) -> MutArr s a b -> a -> b -> ST s ()
  28. primitive primSTFreeze   "STFreeze"
  29.                   :: MutArr s a b -> ST s (Array a b)
  30.  
  31. newArr       :: Ix a => (a,a) -> b -> ST s (MutArr s a b)
  32. newArr bounds = primSTNewArr (index bounds) bounds
  33.  
  34. readArr      :: Ix a => MutArr s a b -> a -> ST s b
  35. readArr       = primSTReadArr index
  36.  
  37. writeArr     :: Ix a => MutArr s a b -> a -> b -> ST s ()
  38. writeArr      = primSTWriteArr index
  39.  
  40. freezeArr    :: Ix a => MutArr s a b -> ST s (Array a b)
  41. freezeArr     = primSTFreeze
  42.  
  43. -----------------------------------------------------------------------------
  44.