Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Unsafe #-}{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module : GHC.STRef-- Copyright : (c) The University of Glasgow, 1994-2002-- License : see libraries/base/LICENSE---- Maintainer : cvs-ghc@haskell.org-- Stability : internal-- Portability : non-portable (GHC Extensions)---- References in the 'ST' monad.-------------------------------------------------------------------------------moduleGHC.STRef(STRef(..),newSTRef,readSTRef,writeSTRef)whereimportGHC.STimportGHC.Base-- $setup-- import PreludedataSTRefsa=STRef(MutVar#sa)-- ^ a value of type @STRef s a@ is a mutable variable in state thread @s@,-- containing a value of type @a@---- >>> :{-- runST (do-- ref <- newSTRef "hello"-- x <- readSTRef ref-- writeSTRef ref (x ++ "world")-- readSTRef ref )-- :}-- "helloworld"-- |Build a new 'STRef' in the current state threadnewSTRef::a->STs(STRefsa)newSTRefinit=ST$\s1#->casenewMutVar#inits1#of{(#s2#,var##)->(#s2#,STRefvar##)}-- |Read the value of an 'STRef'readSTRef::STRefsa->STsareadSTRef(STRefvar#)=ST$\s1#->readMutVar#var#s1#-- |Write a new value into an 'STRef'writeSTRef::STRefsa->a->STs()writeSTRef(STRefvar#)val=ST$\s1#->casewriteMutVar#var#vals1#of{s2#->(#s2#,()#)}-- | Pointer equality.---- @since 2.01instanceEq(STRefsa)whereSTRefv1#==STRefv2#=isTrue#(sameMutVar#v1#v2#)
[8]ページ先頭