1
1
mirror of https://github.com/github/semantic.git synced 2025-01-05 14:11:33 +03:00

Add Show instances.

This commit is contained in:
Rob Rix 2016-02-26 12:32:00 -07:00
parent 55bca5ed1e
commit d5a59ff9b0
2 changed files with 7 additions and 0 deletions

View File

@ -7,6 +7,9 @@ data Cofree functor annotation = annotation :< (functor (Cofree functor annotati
instance (Eq annotation, Eq (functor (Cofree functor annotation))) => Eq (Cofree functor annotation) where
a :< f == b :< g = a == b && f == g
instance (Show annotation, Show (functor (Cofree functor annotation))) => Show (Cofree functor annotation) where
showsPrec n (a :< f) = showsPrec n a . (" :< " ++) . showsPrec n f
unwrap :: Cofree functor annotation -> functor (Cofree functor annotation)
unwrap (_ :< f) = f

View File

@ -9,6 +9,10 @@ instance (Eq pure, Eq (functor (Free functor pure))) => Eq (Free functor pure) w
Free f == Free g = f == g
_ == _ = False
instance (Show pure, Show (functor (Free functor pure))) => Show (Free functor pure) where
showsPrec n (Pure a) = ("Pure " ++) . showsPrec n a
showsPrec n (Free f) = ("Free " ++) . showsPrec n f
iter :: Functor functor => (functor pure -> pure) -> Free functor pure -> pure
iter _ (Pure a) = a
iter f (Free g) = f (iter f <$> g)