{-# LANGUAGE UndecidableInstances, FlexibleContexts, TypeFamilies, KindSignatures #-} module Data.TrieMap.Rep where type family Rep a type family RepT (f :: * -> *) :: * -> * class Repr a where toRep :: a -> Rep a fromRep :: Rep a -> a class Functor (RepT f) => ReprT f where toRepT :: f a -> RepT f a fromRepT :: RepT f a -> f a toRepTMap :: (a -> b) -> f a -> RepT f b fromRepTMap :: (b -> a) -> RepT f b -> f a toRepT = toRepTMap id fromRepT = fromRepTMap id toRepTMap f = fmap f . toRepT fromRepTMap f = fromRepT . fmap f {-# RULES "toRep/fromRep" forall x . toRep (fromRep x) = x; -- "fromRep/toRep" forall x . fromRep (toRep x) = x; #-}