module Data.Type.Coercion ( Coercion(..) , coerceWith , gcoerceWith , sym-- , trans , repr , TestCoercion(..) ) whereimport Data.Coerceimport qualified Data.Type.Equality as Eqdata Coercion a b where Coercion :: Coercible a b => Coercion a bcoerceWith :: Coercion a b -> a -> bcoerceWith Coercion x = coerce xgcoerceWith :: Coercion a b -> (Coercible a b => r) -> rgcoerceWith Coercion x = xsym :: Coercion a b -> Coercion b asym Coercion = Coercion--XXX BUG: mhs does not take the transitive closure.--trans :: Coercion a b -> Coercion b c -> Coercion a c--trans Coercion Coercion = Coercionrepr :: (a Eq.:~: b) -> Coercion a brepr Eq.Refl = Coercionderiving instance Eq (Coercion a b)deriving instance Show (Coercion a b)deriving instance Ord (Coercion a b)deriving instance Coercible a b => Read (Coercion a b)instance Coercible a b => Enum (Coercion a b) where toEnum 0 = Coercion toEnum _ = error "Data.Type.Coercion.toEnum: bad argument" fromEnum Coercion = 0deriving instance Coercible a b => Bounded (Coercion a b)class TestCoercion f where testCoercion :: f a -> f b -> Maybe (Coercion a b)instance TestCoercion ((Eq.:~:) a) where testCoercion Eq.Refl Eq.Refl = Just Coercioninstance TestCoercion ((Eq.:~~:) a) where testCoercion Eq.HRefl Eq.HRefl = Just Coercion--XXX BUG--instance TestCoercion (Coercion a) where-- testCoercion Coercion Coercion = Just Coercion