 marshalCapsModify mkCaps (CapsM action) =
     unsafePerformIO $
         do ptr <- mkCaps
-           caps <- liftM Caps $ newForeignPtr_ ptr
-           result <- action caps
-           caps' <- takeCaps ptr
-           return (caps', result)
-
+           result <- runReaderT action ptr
+           caps <- takeCaps ptr
+           return (caps, result)
+
+-- | Create a caps and mutate it according to the given action.
 capsCreate :: CapsM a
            -> (Caps, a)
 capsCreate action =

    toBool $ unsafePerformIO $
        {# call caps_is_subset #} caps1 caps2

capsIntersect :: Caps
             -> Caps
             -> Caps
capsIntersect caps1 caps2 =
    unsafePerformIO $
        {# call caps_intersect #} caps1 caps2 >>=
            takeCaps

capsUnion :: Caps
          -> Caps
          -> Caps

    toBool $ unsafePerformIO $
        {# call caps_is_always_compatible #} caps1 caps2

-- | Returns 'True' if all caps represented by the first argument are
--   also represented by the second.
--   
--   This function does not work reliably if optional properties for
--   caps are included on one caps and omitted on the other.
capsIsSubset :: Caps
             -> Caps
             -> Bool
