
14 Dec
2017
14 Dec
'17
9:33 a.m.
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