Manuel M. T. Chakravarty chak at
Sun Feb 4 01:15:16 EST 2001

I am just wondering whether we would want to add the
following to `MarshalError':

  -- wrap the result into a `Maybe' type (EXPORTED)
  -- * the predicate determines when the result is considered to be non-existing,
  --   ie, it is represented by `Nothing'
  -- * the second argument allows to map a result wrapped into `Just' to some
  --   other domain
  nothingIf       :: (a -> Bool) -> (a -> b) -> a -> Maybe b
  nothingIf p f x  = if p x then Nothing else Just $ f x

  -- instance for special casing null pointers (EXPORTED)
  nothingIfNull :: (Ptr a -> b) -> Ptr a -> Maybe b
  nothingIfNull  = nothingIf (== nullPtr)

These are the `Maybe' counterparts of the exception routines
in MarshalError.  This style of using `Maybe' for handling
special return values isn't covered by the `Maybe'-related
routines in `MarshalUtils'.


More information about the FFI mailing list