首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么bracket需要` `release` `才能产生被忽略的结果?

为什么bracket需要` `release` `才能产生被忽略的结果?
EN

Stack Overflow用户
提问于 2016-07-17 21:21:25
回答 0查看 61关注 0票数 2
代码语言:javascript
复制
bracket
        :: IO a         -- ^ computation to run first (\"acquire resource\")
        -> (a -> IO b)  -- ^ computation to run last (\"release resource\")
        -> (a -> IO c)  -- ^ computation to run in-between
        -> IO c         -- returns the value from the in-between computation
bracket before after thing =
  mask $ \restore -> do
    a <- before
    r <- restore (thing a) `onException` after a
    _ <- after a
    return r

这是否与某些API设计模式或约定有关?为什么不使用签名的以下部分?

代码语言:javascript
复制
        -> (a -> IO ())  -- ^ computation to run last (empty result)

代码语言:javascript
复制
        -> (a -> IO a)  -- ^ computation to run last (`a` cannot be ignored)
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38421682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档