TY - GEN
T1 - Lightweight monadic regions
AU - Kiselyov, Oleg
AU - Shan, Chung Chieh
PY - 2008
Y1 - 2008
N2 - 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.
AB - 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.
KW - Effect systems
KW - Monads
KW - Parametric polymorphism
KW - Regions
KW - Resource management
KW - Subtyping
KW - Type classes
KW - Type systems
UR - http://www.scopus.com/inward/record.url?scp=63149102574&partnerID=8YFLogxK
UR - http://www.scopus.com/inward/citedby.url?scp=63149102574&partnerID=8YFLogxK
U2 - 10.1145/1411286.1411288
DO - 10.1145/1411286.1411288
M3 - Conference contribution
AN - SCOPUS:63149102574
SN - 9781605580647
T3 - Haskell'08 - Proceedings of the ACM SIGPLAN 2008 Haskell Symposium
SP - 1
EP - 12
BT - Haskell'08 - Proceedings of the ACM SIGPLAN 2008 Haskell Symposium
T2 - 1st ACM SIGPLAN Haskell Symposium, Haskell'08
Y2 - 25 September 2008 through 25 September 2008
ER -