newParser :: (String -> IO ())
          -> Maybe String
          -> IO Parser
newParser errorHandler maybeFilename = do
  inputBufferIORef <- newIORef BS.empty
  beginDocumentCallbackIORef <- newIORef Nothing
  endDocumentCallbackIORef <- newIORef Nothing
  beginElementCallbackIORef <- newIORef Nothing
  endElementCallbackIORef <- newIORef Nothing
  charactersCallbackIORef <- newIORef Nothing
  commentCallbackIORef <- newIORef Nothing
  instructionCallbackIORef <- newIORef Nothing
  doctypeCallbackIORef <- newIORef Nothing
  return Parser {
             parserErrorHandler = errorHandler,
             parserFilename = maybeFilename,
             parserInputBuffer = inputBufferIORef,
             parserBeginDocumentCallback = beginDocumentCallbackIORef,
             parserEndDocumentCallback = endDocumentCallbackIORef,
             parserBeginElementCallback = beginElementCallbackIORef,
             parserEndElementCallback = endElementCallbackIORef,
             parserCharactersCallback = charactersCallbackIORef,
             parserCommentCallback = commentCallbackIORef,
             parserInstructionCallback = instructionCallbackIORef,
             parserDoctypeCallback = doctypeCallbackIORef
           }
newParser :: (String -> IO ())
          -> Maybe String
          -> IO Parser
newParser errorHandler maybeFilename = do
  inputBufferIORef <- newIORef BS.empty
  beginDocumentCallbackIORef <- newIORef Nothing
  endDocumentCallbackIORef <- newIORef Nothing
  beginElementCallbackIORef <- newIORef Nothing
  endElementCallbackIORef <- newIORef Nothing
  charactersCallbackIORef <- newIORef Nothing
  commentCallbackIORef <- newIORef Nothing
  instructionCallbackIORef <- newIORef Nothing
  doctypeCallbackIORef <- newIORef Nothing
  return Parser {
             parserErrorHandler = errorHandler,
             parserFilename = maybeFilename,
             parserInputBuffer = inputBufferIORef,
             parserBeginDocumentCallback = beginDocumentCallbackIORef,
             parserEndDocumentCallback = endDocumentCallbackIORef,
             parserBeginElementCallback = beginElementCallbackIORef,
             parserEndElementCallback = endElementCallbackIORef,
             parserCharactersCallback = charactersCallbackIORef,
             parserCommentCallback = commentCallbackIORef,
             parserInstructionCallback = instructionCallbackIORef,
             parserDoctypeCallback = doctypeCallbackIORef
           }
newParser errorHandler maybeFilename = do
  inputBufferIORef <- newIORef BS.empty
  beginDocumentCallbackIORef <- newIORef Nothing
  endDocumentCallbackIORef <- newIORef Nothing
  beginElementCallbackIORef <- newIORef Nothing
  endElementCallbackIORef <- newIORef Nothing
  charactersCallbackIORef <- newIORef Nothing
  commentCallbackIORef <- newIORef Nothing
  instructionCallbackIORef <- newIORef Nothing
  doctypeCallbackIORef <- newIORef Nothing
  return Parser {
             parserErrorHandler = errorHandler,
             parserFilename = maybeFilename,
             parserInputBuffer = inputBufferIORef,
             parserBeginDocumentCallback = beginDocumentCallbackIORef,
             parserEndDocumentCallback = endDocumentCallbackIORef,
             parserBeginElementCallback = beginElementCallbackIORef,
             parserEndElementCallback = endElementCallbackIORef,
             parserCharactersCallback = charactersCallbackIORef,
             parserCommentCallback = commentCallbackIORef,
             parserInstructionCallback = instructionCallbackIORef,
             parserDoctypeCallback = doctypeCallbackIORef
           }