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

Factor the calculation of the gram into the where clause.

This commit is contained in:
Rob Rix 2016-08-10 15:54:37 -04:00
parent d03ab55c23
commit e162987c26

View File

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