[GHC] #8850: (Compositional) function mkWeakChan

GHC ghc-devs at haskell.org
Wed Mar 5 10:32:16 UTC 2014


#8850: (Compositional) function mkWeakChan
------------------------------------+-------------------------------------
       Reporter:  bholst            |             Owner:
           Type:  feature request   |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  libraries/base    |           Version:  7.6.3
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  Other
     Difficulty:  Unknown           |         Test Case:
     Blocked By:                    |          Blocking:
Related Tickets:  7285              |
------------------------------------+-------------------------------------
 Following the existing functions mkWeakIORef and mkWeakMVar, I'd like to
 have a function mkWeakChan with the following type signature, similar to
 that of mkWeakMVar requested by ticket #7285:

 {{{
 mkWeakChan :: Chan a -> v -> Maybe (IO ()) -> IO (Weak v)
 }}}

 The implementation of '''Chan''' is private, so it is not easily possible
 to implement it yourself. The implementation of both functions may look
 like the following:


 {{{
 mkWeakMVar :: MVar a -> v -> Maybe (IO ()) -> IO (Weak v)
 mkWeakMVar (MVar m#) v (Just f) = IO $ \s ->
   case mkWeak# m# v f s of (# s1, w #) -> (# s1, Weak w #)
 mkWeakMVar (MVar m#) v Nothing  = IO $ \s ->
   case mkWeakNoFinalizer# m# v s of { (# s1, w #) -> (# s1, Weak w #) }

 mkWeakChan :: Chan a -> v -> Maybe (IO ()) -> IO (Weak v)
 mkWeakChan c@(Chan readVar writeVar) v f = do
   _ <- mkWeakMVar readVar  writeVar Nothing
   mkWeakMVar writeVar v f
 }}}

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


More information about the ghc-tickets mailing list