[Haskell-beginners] Why exception is not catching?!

Baa aquagnu at gmail.com
Thu Dec 14 14:33:52 UTC 2017


Hello, dear List!
Super simple function - "safe enum conversion". It's based on `Either`
because only it instantiates `MonadCatch` (Maybe does not, but with
MaybeT I've got error that internal monad Indetity is not MonadCatch,
so I avoid to use Maybe). That it is:

  data A = A1|A2 deriving (Enum, Show)
  data B = B1|B2|B3 deriving (Enum, Show)
  conv :: B -> Either SomeException A
  conv b = safeConv
    where catchError (e::SomeException) = Left e
      safeConv = (Right $ toEnum $ fromEnum b) `catch` catchError
      -- toRes (Left _) = Nothing
      -- toRes (Right r) = Just r

But exception is not catching and I'm getting it in GHCI repl :)
Exceptions are different?! What's wrong with this code?

===
Best regards, Paul


More information about the Beginners mailing list