That works well, but is there an extension free way of doing this cleanly? I tried
On Tue, Nov 22, 2011 at 4:35 AM, Michael Craig <mkscrg@gmail.com> wrote:If you enable the ViewPatterns extension
> ... 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 ...
> handleErrors :: SomeException -> Iteratee a m String
> handleErrors ex = case fromException ex of
> Just POSTOnlyException -> return "POSTs only!"
> _ -> case fromException ex of
> Just BadPathException -> return "Bad path!"
> _ -> return "Unknown exception!"
> ... but there must be a better way. Enlighten me?
{-# LANGUAGE ViewPatterns #-}
then you can write handleErrors as
handleErrors (fromException -> Just POSTOnlyException) = return
handleErrors :: SomeException -> Iteratee a m String
"POSTs only!"
handleErrors (fromException -> Just BadPathException) = return "Bad path!"
handleErrors _ = return "Unknown exception!"
Cheers,
--
Felipe.