简体   繁体   中英

Looking at the value of a TVar in GHCi

Working through Simon Peyton Jones concurrency example, I have the following code:

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

*Main> checking <- atomically $ newTVar 100
*Main> atomically $ deposit checking 10

How do I verify my checking balance is $110?

I have tried

*Main> checking
*Main> readTVar checking
*Main> balance <- readTVar checking

atomically $ readTVar checking does what you want. The GHCi REPL automatically executes any IO action that you give it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM