I have a piece of code where inside a list monad, a function is applied. Function may potentially have non-exhaustive pattern matching for its arguments. Therefore when the function is applied, I might get "Non-exhaustive pattern matching" error. I would like to turn this error into a monadic fail (in this case, an empty list). In other words I would like to get a similar behavior to what happens when Some Pattern Here <- some value inside a do block fails.
Question: Is there an efficient way to make a function application safe? By efficient I mean something that would be analogous to making the applied function match exhaustively and fail explicitly.
One option would be to use spoon to convert the function from one that throws exceptions into one that returns
Maybe avalues. Then it should be a simple matter of convertingNothingto[].