[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] Functor instance for weak pointers?
From:       David Roundy <droundy () abridgegame ! org>
Date:       2004-08-29 17:40:20
Message-ID: 20040829174020.GB17869 () abridgegame ! org
[Download RAW message or body]

Might it be possible to create a Functor instance for weak pointers?

I don't really need to, but it would certainly be handy.  Unfortunately, I
don't see how it could be implemented, since there's no way to create a new
already-tombstoned weak pointer, and without that ability, I can't see how
one could do this.

I'd like to write

weakFmap :: (a -> b) -> Weak a -> Weak b

but don't see how I can, since if deRefWeak returns Nothing, I have no way
of creating a Weak b that will also return Nothing.  :( A simple

emptyWeak :: Weak a

would be sufficient, as I could then write

weakFmap f wa = unsafePerformIO $ do ma <- deRefWeak wa
                                     case ma of
                                       Nothing -> return emptyWeak
                                       Just b -> mkWeakPtr (f b) Nothing
-- 
David Roundy
http://www.abridgegame.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic