haskell - What approach to error handling to use with pipes(-core)? -


I am currently writing some pipe-core / etuppressive pipelines for a small project. I want to give a pipe giving pipe to each parser pipe that waits for byteestring input to pars and receives any parsed values ​​(restart parser) . Without handling the error, such a type of

  Parser :: Monad M => Parser a -> Pipe Byte String An M   

Now, what I have to do with parse errors is uncertain my current thoughts are as follows:

  • Errors To add return type (i.e. return to either or parseError r just return a value in r )
  • To provide error handling mechanism Is required (i.e. Madad required that the pipe to implement MonadError
  • For the any monad m
  • supply the error mechanism by taking it on the pipe, Add parameter, specify the user

    The first solution seems incorrect, using a pipe return type to operate the error seems like a hack, for this one thing, the pipe creates the Eugeler and the final solution (or possibly a Downstream pipe In addition to losing the ability to be able to recover from Ti) to try and stop waiting for values?).

    The second solution seems to be wrong, why can not I keep my finger why maybe it (will?) Also take Parameters to translate the parameter into any error type parameter (Unless we do not want to apply Monad to MonadError ParseError , lots to keep the book) Finally, I think that MonadError Looks like it's too much That is, there is some problem with using it, can not remember.

    The third solution will work in my case, because the pipe user will be part of a pipeline with the specified moond (Io), which does not care for the parsing errors (this network data is not assigned to any specified type Will be found in the format). But that does not look elegant at all, and then, (possibly?), Will result in many books used once in any other context.

    I have not really thought through the final solution

    I would be grateful for any thoughts on this particular matter (I would not be surprised at all if I am stopping the path And some is more obvious), and reference to discussions on dealing with errors in pipes (-cor) / tubules / interacs etc.

    EDIT: Another possibility may be to take only one monaadiic action (instead of a full-blown pipe), although I'm not completely sure that it can be just about generalization, expert or fourth. "post-text" itemprop = "text">

    If I can, then I think that by describing the choice I like about it, in order to organize everyone's thoughts on it. Can help You can either:

    1. Layer pipe within a / error :

      ATT E (Pipe ABM) R

    2. Layer pipe a outside of / error T < / Code>:

      Pipe AB (ATM) R

      You want a pre-approach, which also has good assets that you can make it MonadError Example (if this is your thing).

      To understand the difference between two methods, the other throws errors at the whole pipeline level. The first person allows handling of individual pipes with error on the granulity and handles the stored pipes properly.

      For some code now. If you do not mind, I will use it for its use because I'm more comfortable with it:

        Import control Error import control Pipe type pipe e eabmr = EitherT e (pipe abm) r RunPipeE = runPipe RunEitherT p1 & lt ;? & Lt;          

      The advantage, that is, you will find some areas of select pipeline You can apply it in, but then you are responsible for handling potentially extraordinary value before writing it with other pipes. You can use the flexibility to use different types of extraordinary values ​​for different stages of the pipeline or not to use that phase which can not be unsuccessful, and from the overhead of error-checking of those steps Can escape.

Comments