Plaster

haskell
data T = A Int | B Bool class Wrappable r where wrap :: r -> T instance Wrappable Int where wrap x = A x instance Wrappable Bool where wrap x = B x data T' a = A' (Either Int a) | B' (Either Bool a) class Wrappable' r where wrap' :: r -> T' a instance Wrappable' (Either Int a) where wrap' x = A' x instance Wrappable' (Either Bool a) where wrap' x = B' x -- fix T', but how to use wrap'? data T' a = A' (Either Int a) | B' (Either Bool a) class Wrappable' a r where wrap' :: r -> T' a instance Wrappable' a (Either Int a) where wrap' x = A' x instance Wrappable' a (Either Bool a) where wrap' x = B' x -- fix both T' and wrap', this works data T' a = A' (Either Int a) | B' (Either Bool a) class Wrappable' a b where wrap' :: (Either a b) -> T' b instance Wrappable' Int (Either Int b) where wrap' x = A' x instance Wrappable' Bool (Either Bool b) where wrap' x = B' x foo :: Wrappable' Bool b => T' b foo = wrap' $ Left True -- more clear data T' a = A' (Either Int a) | B' (Either Bool a) class Wrappable' a b where wrap' :: (Either a b) -> T' b instance Wrappable' Int b where wrap' x = A' x instance Wrappable' Bool b where wrap' x = B' x foo :: T' b foo = wrap' $ Left True