Lightweight monadic regions

O. Kiselyov, Chung-chieh Shan
{"title":"Lightweight monadic regions","authors":"O. Kiselyov, Chung-chieh Shan","doi":"10.1145/1411286.1411288","DOIUrl":null,"url":null,"abstract":"We present Haskell libraries that statically ensure the safe use of resources such as file handles. We statically prevent accessing an already closed handle or forgetting to close it. The libraries can be trivially extended to other resources such as database connections and graphic contexts.\n Because file handles and similar resources are scarce, we want to not just assure their safe use but further deallocate them soon after they are no longer needed. Relying on Fluet and Morrisett's [4] calculus of nested regions, we contribute a novel, improved, and extended implementation of the calculus in Haskell, with file handles as resources.\n Our library supports region polymorphism and implicit region subtyping, along with higher-order functions, mutable state, recursion, and run-time exceptions. A program may allocate arbitrarily many resources and dispose of them in any order, not necessarily LIFO. Region annotations are part of an expression's inferred type.\n Our new Haskell encoding of monadic regions as monad transformers needs no witness terms. It assures timely deallocation even when resources have markedly different lifetimes and the identity of the longest-living resource is determined only dynamically.\n For contrast, we also implement a Haskell library for manual resource management, where deallocation is explicit and safety is assured by a form of linear types. We implement the linear typing in Haskell with the help of phantom types and a parameterized monad to statically track the type-state of resources.","PeriodicalId":188691,"journal":{"name":"ACM SIGPLAN Symposium/Workshop on Haskell","volume":"62 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2008-09-25","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"35","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Symposium/Workshop on Haskell","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1411286.1411288","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 35

Abstract

We present Haskell libraries that statically ensure the safe use of resources such as file handles. We statically prevent accessing an already closed handle or forgetting to close it. The libraries can be trivially extended to other resources such as database connections and graphic contexts. Because file handles and similar resources are scarce, we want to not just assure their safe use but further deallocate them soon after they are no longer needed. Relying on Fluet and Morrisett's [4] calculus of nested regions, we contribute a novel, improved, and extended implementation of the calculus in Haskell, with file handles as resources. Our library supports region polymorphism and implicit region subtyping, along with higher-order functions, mutable state, recursion, and run-time exceptions. A program may allocate arbitrarily many resources and dispose of them in any order, not necessarily LIFO. Region annotations are part of an expression's inferred type. Our new Haskell encoding of monadic regions as monad transformers needs no witness terms. It assures timely deallocation even when resources have markedly different lifetimes and the identity of the longest-living resource is determined only dynamically. For contrast, we also implement a Haskell library for manual resource management, where deallocation is explicit and safety is assured by a form of linear types. We implement the linear typing in Haskell with the help of phantom types and a parameterized monad to statically track the type-state of resources.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
轻量级单元区域
我们提供的Haskell库可以静态地确保资源(如文件句柄)的安全使用。我们静态地防止访问已经关闭的句柄或忘记关闭它。这些库可以简单地扩展到其他资源,如数据库连接和图形上下文。因为文件句柄和类似的资源是稀缺的,所以我们不仅要确保它们的安全使用,还要在不再需要它们之后尽快重新分配它们。依靠Fluet和Morrisett的[4]嵌套区域演算,我们在Haskell中贡献了一种新颖的、改进的和扩展的演算实现,以文件句柄作为资源。我们的库支持区域多态性和隐式区域子类型,以及高阶函数、可变状态、递归和运行时异常。程序可以分配任意数量的资源,并以任意顺序处理它们,不一定是后进先出。区域注释是表达式推断类型的一部分。我们的单元区域的新Haskell编码作为单元转换器不需要见证项。即使资源具有明显不同的生命周期,并且寿命最长的资源的身份仅动态确定,它也可以确保及时的重新分配。相比之下,我们还实现了一个用于手动资源管理的Haskell库,其中的释放是显式的,并且通过线性类型的形式保证了安全性。我们在Haskell中使用幻影类型和参数化单子来实现线性类型,以静态跟踪资源的类型状态。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Mio: a high-performance multicore io manager for GHC Understanding idiomatic traversals backwards and forwards An EDSL approach to high performance Haskell programming Causality of optimized Haskell: what is burning our cycles? Splittable pseudorandom number generators using cryptographic hashing
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1