[英]Looking at the value of a TVar in GHCi
Working through Simon Peyton Jones concurrency example, I have the following code: 通过Simon Peyton Jones并发示例,我有以下代码:
import Control.Concurrent.STM
import Control.Concurrent.STM.TVar
deposit account amount = do
bal <- readTVar account
writeTVar account (bal+amount)
I am trying to test this in GHCi REPL 我试图在GHCi REPL中测试这个
*Main> checking <- atomically $ newTVar 100
*Main> atomically $ deposit checking 10
How do I verify my checking balance is $110? 如何验证我的支票余额是110美元?
I have tried 我试过了
*Main> checking
*Main> readTVar checking
*Main> balance <- readTVar checking
atomically $ readTVar checking
does what you want. atomically $ readTVar checking
做你想要的。 The GHCi REPL automatically executes any IO action that you give it. GHCi REPL自动执行您提供的任何IO操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.