I am attempting to pattern match on a type in a case statement such as the following:
result <- action
case result of
Success _ -> do something
Failure e -> case e of
MyException myField -> do take another action
_ -> ...
The compiler can’t deduce e ~ MyException which I understand. My question is what other information do I need to supply to the compiler to be able to match my exception type. In this particular case I know that if there is a Failure the returned type will be MyException.
EDIT:
The type of result (From the Aws package) is:
(Transaction r a, ConfigurationFetch (Info r)) =>
Configuration -> r -> IO (Response (ResponseMetadata a) a)
a is from Data.Attempt which is either a Success or Failure.
Assuming you’re using extensible exceptions (which is the default in recent ghc’s), your result is probably something like
You need to convert the
SomeExceptionto your own exception type. This is done with the functiontoException :: Exception e => SomeException -> Maybe e. Then you would handle this like:Of course this is assuming that I’m right about your
Resulttype.