Skip to content

Instantly share code, notes, and snippets.

@xplat
Last active August 22, 2018 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xplat/5573171c57076bd1e67cfc57d4fe1bee to your computer and use it in GitHub Desktop.
Save xplat/5573171c57076bd1e67cfc57d4fe1bee to your computer and use it in GitHub Desktop.
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