module Data.Tupler
(
Pair1(..), Pair2(..)
) where
import Data.Typeable
newtype Pair1 f g a = Pair1 {unPair1 :: (f a, g a)}
deriving (Eq, Ord, Show)
instance (Typeable1 f, Typeable1 g) => Typeable1 (Pair1 f g) where
typeOf1 = const $ mkTyConApp (mkTyCon tyConStr) []
where
tyConStr = "Data.Tupler.Pair1"
++ tcStringSP (undefined :: f Bool)
++ tcStringSP (undefined :: g Bool)
newtype Pair2 f g a b = Pair2 {unPair2 :: (f a b, g a b)}
deriving (Eq, Ord, Show)
instance (Typeable2 f, Typeable2 g) => Typeable2 (Pair2 f g) where
typeOf2 = const $ mkTyConApp (mkTyCon tyConStr) []
where
tyConStr = "Data.Tupler.Pair2"
++ tcStringSP (undefined :: f Bool Bool)
++ tcStringSP (undefined :: g Bool Bool)
parensIfSpace :: String -> String
parensIfSpace str | ' ' `elem` str = "("++str++")"
| otherwise = str
tcString :: Typeable a => a -> String
tcString = tyConString . typeRepTyCon . typeOf
tcStringP :: Typeable a => a -> String
tcStringP = parensIfSpace . tcString
tcStringSP :: Typeable a => a -> String
tcStringSP = (' ':) . tcStringP