The withMutablePrimArrayContents and withPrimArrayContents functions take a Ptr a -> m a, which restricts you to only returning an a. Best guess as to why this might have been done is to prevent the return of the pointer itself, but... it prevents the return of everything else too ... Why not change them to (Ptr a -> m b) -> m b?