witch/src/lib/Witch/TryCastException.hs

36 lines
1.0 KiB
Haskell
Raw Normal View History

{-# LANGUAGE ScopedTypeVariables #-}
module Witch.TryCastException where
import qualified Control.Exception as Exception
import qualified Data.Proxy as Proxy
import qualified Data.Typeable as Typeable
2021-04-18 21:01:05 +03:00
-- | This exception is thrown when a @TryCast@ conversion fails. It has the
-- original @source@ value that caused the failure and it knows the @target@
-- type it was trying to convert into.
2021-04-23 16:01:03 +03:00
data TryCastException source target = TryCastException
source
(Maybe Exception.SomeException)
instance
( Show source
, Typeable.Typeable source
, Typeable.Typeable target
2021-04-17 17:17:32 +03:00
) => Show (TryCastException source target) where
showsPrec d (TryCastException x e) =
2021-04-18 18:28:02 +03:00
showParen (d > 10)
$ showString "TryCastException {- "
. shows
(Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy (source -> target)))
. showString " -} "
. showsPrec 11 x
. showChar ' '
. showsPrec 11 e
2021-04-17 17:17:32 +03:00
instance
( Show source
, Typeable.Typeable source
, Typeable.Typeable target
) => Exception.Exception (TryCastException source target)