1 2 3 4 5 6 7 8 9 10 11 12 | {-# LANGUAGE ExistentialQuantification, TypeFamilies #-} module Test where data Foo a = (a ~ Int) => Foo1 String | (a ~ String) => Foo2 Int instance Show (Foo a) where show (Foo1 s) = "Foo1 " ++ show s show (Foo2 n) = "Foo2 " ++ show n f :: a -> Foo a -> Foo a f n (Foo1 s) = Foo1 $ concat $ replicate n s f s (Foo2 n) = Foo2 $ n * length s |