Quoth Dimitry Golubovsky <[email protected]>,

> Is there any way to catch/detect failures inside the Get monad? It is
> not an instance of MonadError, so catchError does not work.
>
> Ideally, the function would keep decoding as long as it is possible,
> and upon the first failure of the parser, return whatever has been
> decoded.

I believe it can't be done.  (I've seen three responses that seemed
to be proposing some course of action, but ... correct me if I'm wrong,
nothing that would allow you to use Get in Data.Binary this way.)

The key point is the use of `throw', via `error', in Get's `fail'.
`throw' raises an exception that can be caught only in IO, so you
can't catch it inside Get.  So ... while `fail' is a Monad function,
it isn't implemented here in a way you could use, like it is in Maybe
for example.  Nor could it be, I think, which is kind of unfortunate.

        Donn Cave, [email protected]
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to