mirror of
https://github.com/github/semantic.git
synced 2024-12-19 21:01:35 +03:00
🔥 zipTerms.
This commit is contained in:
parent
fe3fa0e811
commit
ee27d73747
@ -4,7 +4,6 @@ module Term
|
|||||||
, TermF(..)
|
, TermF(..)
|
||||||
, SyntaxTerm
|
, SyntaxTerm
|
||||||
, SyntaxTermF
|
, SyntaxTermF
|
||||||
, zipTerms
|
|
||||||
, termSize
|
, termSize
|
||||||
, alignTermWith
|
, alignTermWith
|
||||||
, cofree
|
, cofree
|
||||||
@ -18,9 +17,7 @@ import Control.Comonad
|
|||||||
import Control.Comonad.Cofree.Class
|
import Control.Comonad.Cofree.Class
|
||||||
import Control.DeepSeq
|
import Control.DeepSeq
|
||||||
import Control.Monad.Free
|
import Control.Monad.Free
|
||||||
import Data.Align.Generic
|
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.Functor.Both
|
|
||||||
import Data.Functor.Classes
|
import Data.Functor.Classes
|
||||||
import Data.Functor.Classes.Pretty.Generic as Pretty
|
import Data.Functor.Classes.Pretty.Generic as Pretty
|
||||||
import Data.Functor.Foldable
|
import Data.Functor.Foldable
|
||||||
@ -49,12 +46,6 @@ instance (NFData (f (Term f a)), NFData a, Functor f) => NFData (Term f a) where
|
|||||||
instance (NFData a, NFData (f b)) => NFData (TermF f a b) where
|
instance (NFData a, NFData (f b)) => NFData (TermF f a b) where
|
||||||
rnf (a :<< s) = rnf a `seq` rnf s `seq` ()
|
rnf (a :<< s) = rnf a `seq` rnf s `seq` ()
|
||||||
|
|
||||||
-- | Zip two terms by combining their annotations into a pair of annotations.
|
|
||||||
-- | If the structure of the two terms don't match, then Nothing will be returned.
|
|
||||||
zipTerms :: (Traversable f, GAlign f) => Term f annotation -> Term f annotation -> Maybe (Term f (Both annotation))
|
|
||||||
zipTerms t1 t2 = iter go (alignTermWith galign (const Nothing) both (These t1 t2))
|
|
||||||
where go (a :<< s) = (a :<) <$> sequenceA s
|
|
||||||
|
|
||||||
-- | Return the node count of a term.
|
-- | Return the node count of a term.
|
||||||
termSize :: (Foldable f, Functor f) => Term f annotation -> Int
|
termSize :: (Foldable f, Functor f) => Term f annotation -> Int
|
||||||
termSize = cata size where
|
termSize = cata size where
|
||||||
|
Loading…
Reference in New Issue
Block a user