Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1389
  • 博文数量: 1
  • 博客积分: 192
  • 博客等级: 二等列兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-10 11:15
文章分类

全部博文(1)

文章存档

2012年(1)

我的朋友
最近访客

分类: Delphi

2012-07-30 22:21:53

Haskell 类型系统使STM Monad中不允许存在IO Monad,  然而atomically 的函数签名是STM a -> IO a,使函数类型为" ... -> STM (IO ())",可达到有限度混入IO的目的。例如:

module Main where

import Control.Concurrent.STM

withdraw account amount = do
   (id, bal) <- readTVar account
   check(amount <= 0 || bal >= amount )
   writeTVar account (id, (bal-amount))
   return $ putStrLn $ "withdraw " ++ show amount ++ " from " ++ id
关于STM的介绍,可见Beautiful Code(《代码之美》)第24章Beautiful Concurrency、和。
阅读(148) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~