Last active
August 22, 2018 15:36
-
-
Save xplat/5573171c57076bd1e67cfc57d4fe1bee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype WrappedShow1 f a = WrappedShow1 (f a) | |
instance (Show1 f, Show a) => Show (WrappedShow1 f a) where | |
showsPrec x = liftShowsPrec showsPrec showList | |
showList x = liftShowList showsPrec showList | |
-- instance Show1 YourThing where | |
-- liftShowsPrec = reifyShow (const showsPrec) () | |
-- liftShowList = reifyShow (const showList) () | |
data ReifiedShow a = ReifiedShow { reifiedShowsPrec :: Int -> a -> ShowS, reifiedShowList :: [a] -> ShowS } | |
instance Reifies s (ReifiedShow a) => Show (ReflectedShow a s) where | |
showsPrec prec p@(ReflectedShow x) = reifiedShowsPrec (reflect p) prec s | |
showList xs = reifiedShowList (reflect (head xs) (coerce xs)) | |
newtype ReflectedShow a s = ReflectedShow a | |
unreflectedShow :: ReflectedShow a s -> proxy s -> a | |
unreflectedShow (ReflectedShow a) _ = a | |
reifyShow :: (a -> a -> a) -> a -> (forall (s :: *). Reifies s (ReifiedShow a) => t -> ReflectedShow a s) -> t -> a | |
reifyShow f z m xs = reify (ReifiedShow f z) (unreflectedShow (m xs)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment