[GHC] #8088: Disposable types language extension

GHC ghc-devs at haskell.org
Wed Jul 24 02:04:07 CEST 2013


#8088: Disposable types language extension
----------------------------------------------+----------------------------
       Reporter:  schyler                     |             Owner:
           Type:  feature request             |            Status:  new
       Priority:  normal                      |         Milestone:
      Component:  Compiler                    |           Version:
       Keywords:                              |  Operating System:
   Architecture:  Unknown/Multiple            |  Unknown/Multiple
     Difficulty:  Moderate (less than a day)  |   Type of failure:
     Blocked By:                              |  None/Unknown
Related Tickets:                              |         Test Case:
                                              |          Blocking:
----------------------------------------------+----------------------------
 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.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8088>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler




More information about the ghc-tickets mailing list