1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Define a Foldable instance for Term.

This commit is contained in:
Rob Rix 2017-09-09 12:02:11 +01:00
parent a358be60cc
commit ce02539dab

View File

@ -74,6 +74,9 @@ instance Functor f => Comonad (Term f) where
instance Functor f => Functor (Term f) where instance Functor f => Functor (Term f) where
fmap f = go where go (Term (a :< r)) = Term (f a :< fmap go r) fmap f = go where go (Term (a :< r)) = Term (f a :< fmap go r)
instance Foldable f => Foldable (Term f) where
foldMap f = go where go (Term (a :< r)) = f a `mappend` foldMap go r
instance Functor f => ComonadCofree f (Term f) where instance Functor f => ComonadCofree f (Term f) where
unwrap (Term (_ :< as)) = as unwrap (Term (_ :< as)) = as
{-# INLINE unwrap #-} {-# INLINE unwrap #-}