Hi,

I'd like to write a data structure to be used inside the IO monad.
The structure has some handles of type Maybe (IORef a),
i.e. IORef are pointers and the Maybe is like null pointers.

So I came up with the following functions :

readHandle :: Maybe (IORef a) -> IO (Maybe a)
readField :: (a -> b) -> Maybe (IORef a) -> IO (Maybe b)

readHandle Nothing  = do
  return Nothing
readHandle (Just r) = do
  v <- readIORef r
  return $ Just v

readField f h = do
  m <- readHandle h
  return $ fmap f m

Is it something usual ?
Are there any related functions in the standard libraries ?

Thanks,
Thu
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to