-----------------------------------------------------------------------------
---
+-- |
-- Module : System.Mem.Weak
-- Copyright : (c) The University of Glasgow 2001
--- License : BSD-style (see the file libraries/core/LICENSE)
+-- License : BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: Weak.hs,v 1.1 2001/06/28 14:15:04 simonmar Exp $
---
-- Weak references, weak pairs, weak pointers, and finalizers.
--
-----------------------------------------------------------------------------
import Prelude
-#include "Dynamic.h"
-INSTANCE_TYPEABLE0(Weak,weakTc,"Weak")
+import Data.Dynamic
#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.IOBase
import GHC.Weak
+#include "Dynamic.h"
+INSTANCE_TYPEABLE1(Weak,weakTc,"Weak")
+
deRefWeak :: Weak v -> IO (Maybe v)
deRefWeak (Weak w) = IO $ \s ->
case deRefWeak# w s of
(# s1, 0#, _ #) -> (# s1, () #) -- already dead, or no finaliser
(# s1, _, f #) -> f s1
#endif
+