Skip to content

Disposable types language extension

The disposable types language extension would serve as a way of allowing the garbage collector to clean up things which require destroying handles, closing resources, etc to prevent resource exhaustion in code (even if exceptions occur) without adding transformer overhead like ResourceT.

Consider the following example:

{-# LANGUAGE DisposableTypes #-}

class Dispose t where
    dispose :: t -> IO ()

instance Dispose SockHandle where
    dispose = disconnect

When the SockHandle is collected, the garbage collector runs its dispose method (and it's automatically disconnected and cleaned up). Similar principles could be applied to a file handle, shared memory etc.

Trac metadata
Trac field Value
Version
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information