<div>I have some exception types defined ...</div><div><br></div><div><div> data POSTOnlyException = POSTOnlyException</div><div> deriving ( Show, Typeable )</div><div> instance Exception POSTOnlyException</div>
<div><br></div><div> data BadPathException = BadPathException</div><div> deriving ( Show, Typeable )</div><div> instance Exception BadPathException</div></div><div><br></div><div>... and I want to use Data.Enumerator.catchError ...</div>
<div><br></div><div> catchError :: Monad m => Iteratee a m b -> (SomeException -> Iteratee a m b) -> Iteratee a m b</div><div><br></div><div>... so I define an error handler ...</div><div><br></div><div> handleErrors :: SomeException -> Iteratee a m String</div>
<div> handleErrors ex = case fromException ex of</div><div> Just POSTOnlyException -> return "POSTs only!"</div><div> Just BadPathException -> return "Bad path!"</div><div> _ -> return "Unknown exception!"</div>
<div><br></div><div>... but of course this doesn't compile, because the types of the LHSs in the case statement are different. I can get around it with some ugliness ...</div><div><br></div><div><div> handleErrors :: SomeException -> Iteratee a m String</div>
<div> handleErrors ex = case fromException ex of</div><div> Just POSTOnlyException -> return "POSTs only!"</div><div> _ -> case fromException ex of</div><div> Just BadPathException -> return "Bad path!"</div>
<div> _ -> return "Unknown exception!"</div></div><div><br></div><div>... but there must be a better way. Enlighten me?</div><div><br></div><div>Cheers,</div>Mike S Craig