Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Unsafe #-}{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- 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)newSTRef :: a -> ST s (STRef s a)newSTRefainit=STRep s (STRef s a) -> ST s (STRef s a)forall s a. STRep s a -> ST s aST(STRep s (STRef s a) -> ST s (STRef s a))-> STRep s (STRef s a) -> ST s (STRef s a)forall a b. (a -> b) -> a -> b$\State# ss1#->casea -> State# s -> (# State# s, MutVar# s a #)forall a d. a -> State# d -> (# State# d, MutVar# d a #)newMutVar#ainitState# ss1#of{(#State# ss2#,MutVar# s avar##)->(#State# ss2#,MutVar# s a -> STRef s aforall s a. MutVar# s a -> STRef s aSTRefMutVar# s avar##)}-- |Read the value of an 'STRef'readSTRef::STRefsa->STsareadSTRef :: STRef s a -> ST s areadSTRef(STRefMutVar# s avar#)=STRep s a -> ST s aforall s a. STRep s a -> ST s aST(STRep s a -> ST s a) -> STRep s a -> ST s aforall a b. (a -> b) -> a -> b$\State# ss1#->MutVar# s a -> STRep s aforall d a. MutVar# d a -> State# d -> (# State# d, a #)readMutVar#MutVar# s avar#State# ss1#-- |Write a new value into an 'STRef'writeSTRef::STRefsa->a->STs()writeSTRef :: STRef s a -> a -> ST s ()writeSTRef(STRefMutVar# s avar#)aval=STRep s () -> ST s ()forall s a. STRep s a -> ST s aST(STRep s () -> ST s ()) -> STRep s () -> ST s ()forall a b. (a -> b) -> a -> b$\State# ss1#->caseMutVar# s a -> a -> State# s -> State# sforall d a. MutVar# d a -> a -> State# d -> State# dwriteMutVar#MutVar# s avar#avalState# ss1#of{State# ss2#->(#State# ss2#,()#)}-- | Pointer equality.---- @since 2.01instanceEq(STRefsa)whereSTRefMutVar# s av1#== :: STRef s a -> STRef s a -> Bool==STRefMutVar# s av2#=Int# -> BoolisTrue#(MutVar# s a -> MutVar# s a -> Int#forall d a. MutVar# d a -> MutVar# d a -> Int#sameMutVar#MutVar# s av1#MutVar# s av2#)

[8]ページ先頭

©2009-2025 Movatter.jp