user2847643
user2847643

Reputation: 2935

Terminate xeno SAX parser early

xeno is a fast XML parsing library. It's SAX-style parsing function has the following type:

process
  :: Monad m
  => (ByteString -> m ()) -- ^ Open tag.
  -> (ByteString -> ByteString -> m ()) -- ^ Tag attribute.
  -> (ByteString -> m ()) -- ^ End open tag.
  -> (ByteString -> m ()) -- ^ Text.
  -> (ByteString -> m ()) -- ^ Close tag.
  -> (ByteString -> m ()) -- ^ CDATA.
  -> ByteString
  -> m ()

Is there is a choice of m that would allow to terminate process early from within a handler? By terminate early I mean process exits without processing the rest of the document i.e. no additional work.

I'm aware it can be done using IO and exceptions. Can it be done in IO without using exceptions for control flow? Can it be done without IO?

From the type above can we even tell for sure or would we also need to know the definition of process?

Edit:

Please assume m needs to support state and that state needs to be available after short-circuiting.

Upvotes: 1

Views: 92

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153352

You can know for sure just from the type signature of process, without seeing its implementation: the answer is unequivocally "yes, you can cause it to terminate early". ExceptT is the canonical early-exit monad transformer family. Use throwE or throwError to terminate control flow immediately.

Upvotes: 1

Related Questions