# safer-file-handles: Type-safe file handling

[ bsd3, library, monadic-regions, system ] [ Propose Tags ]

This package adds three safety features on top of the regular System.IO file handles and operations:

• Regional file handles. Files must be opened in a region. When the region terminates all opened files are automatically closed. The main advantage of regions is that the handles to the opened files can not be returned from the region which ensures no I/O with closed files is possible.

• Explicit IOModes. The regional file handles are parameterized by the IOMode in which they were opened. All operations on handles explicitly specify the needed IOMode. This way it is impossible to read from a write-only handle or write to a read-only handle for example.

• Type-safe filepath creation and manipulation using the pathtype package.

The primary technique used in this package is called "Lightweight monadic regions" which was invented by Oleg Kiselyov and Chung-chieh Shan. See:

This technique is implemented in the regions package which is re-exported from safer-file-handles.

See the safer-file-handles-examples package for examples how to use this package:

darcs get http://code.haskell.org/~basvandijk/code/safer-file-handles-examples

See the safer-file-handles-bytestring/text package for ByteString/Text operations on regional file handles.