1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Factor the base & stem assignment into the where clause.

This commit is contained in:
Rob Rix 2016-08-10 15:57:55 -04:00
parent e162987c26
commit 704ff4db08

View File

@ -68,8 +68,9 @@ pqGramDecorator :: Traversable f
-> Cofree f (Record (Gram label ': fields)) -- ^ The decorated term. -> Cofree f (Record (Gram label ': fields)) -- ^ The decorated term.
pqGramDecorator getLabel p q = cata algebra pqGramDecorator getLabel p q = cata algebra
where algebra term = let label = getLabel term in where algebra term = let label = getLabel term in
cofree ((gram label .: headF term) :< (`evalState` (siblingLabels (tailF term))) (for (tailF term) (assignLabels label))) cofree ((gram label .: headF term) :< assignParentAndSiblingLabels (tailF term) label)
gram label = Gram (padToSize p []) (padToSize q (pure (Just label))) gram label = Gram (padToSize p []) (padToSize q (pure (Just label)))
assignParentAndSiblingLabels functor label = (`evalState` (siblingLabels functor)) (for functor (assignLabels label))
assignLabels :: label -> Cofree f (Record (Gram label ': fields)) -> State [Maybe label] (Cofree f (Record (Gram label ': fields))) assignLabels :: label -> Cofree f (Record (Gram label ': fields)) -> State [Maybe label] (Cofree f (Record (Gram label ': fields)))
assignLabels label a = case runCofree a of assignLabels label a = case runCofree a of
RCons gram rest :< functor -> do RCons gram rest :< functor -> do