mirror of
https://github.com/github/semantic.git
synced 2025-01-05 05:58:34 +03:00
Replace the old iterAp with the one taking a continuation.
This commit is contained in:
parent
b5d6b4dbce
commit
9b3d8a4949
@ -16,15 +16,9 @@ data AlgorithmF term diff result where
|
|||||||
-- | The free applicative for 'AlgorithmF'. This enables us to construct diff values using <$> and <*> notation.
|
-- | The free applicative for 'AlgorithmF'. This enables us to construct diff values using <$> and <*> notation.
|
||||||
type Algorithm term diff = Ap (AlgorithmF term diff)
|
type Algorithm term diff = Ap (AlgorithmF term diff)
|
||||||
|
|
||||||
-- | Tear down an Ap by iteration.
|
|
||||||
iterAp :: Functor g => (g a -> a) -> Ap g a -> a
|
|
||||||
iterAp algebra = go
|
|
||||||
where go (Pure a) = a
|
|
||||||
go (Ap underlying apply) = algebra (go . (apply <*>) . pure <$> underlying)
|
|
||||||
|
|
||||||
-- | Tear down an Ap by iteration, given a continuation.
|
-- | Tear down an Ap by iteration, given a continuation.
|
||||||
iterAp' :: (forall x. g x -> (x -> a) -> a) -> Ap g a -> a
|
iterAp :: (forall x. g x -> (x -> a) -> a) -> Ap g a -> a
|
||||||
iterAp' algebra = go
|
iterAp algebra = go
|
||||||
where go (Pure a) = a
|
where go (Pure a) = a
|
||||||
go (Ap underlying apply) = algebra underlying (go . (apply <*>) . pure)
|
go (Ap underlying apply) = algebra underlying (go . (apply <*>) . pure)
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ runAlgorithm :: (GAlign f, HasField fields Category, Eq (f (Cofree f Category)),
|
|||||||
-> SES.Cost (Free (CofreeF f (Both (Record fields))) (Patch (Cofree f (Record fields)))) -- ^ A function to compute the cost of a given diff node.
|
-> SES.Cost (Free (CofreeF f (Both (Record fields))) (Patch (Cofree f (Record fields)))) -- ^ A function to compute the cost of a given diff node.
|
||||||
-> Algorithm (Cofree f (Record fields)) (Free (CofreeF f (Both (Record fields))) (Patch (Cofree f (Record fields)))) a -- ^ The algorithm to run.
|
-> Algorithm (Cofree f (Record fields)) (Free (CofreeF f (Both (Record fields))) (Patch (Cofree f (Record fields)))) a -- ^ The algorithm to run.
|
||||||
-> a
|
-> a
|
||||||
runAlgorithm construct recur cost = iterAp' $ \ r cont -> case r of
|
runAlgorithm construct recur cost = iterAp $ \ r cont -> case r of
|
||||||
Linear a b -> cont . maybe (replacing a b) (construct . (both (extract a) (extract b) :<)) $ do
|
Linear a b -> cont . maybe (replacing a b) (construct . (both (extract a) (extract b) :<)) $ do
|
||||||
aligned <- galign (unwrap a) (unwrap b)
|
aligned <- galign (unwrap a) (unwrap b)
|
||||||
traverse (these (Just . deleting) (Just . inserting) recur) aligned
|
traverse (these (Just . deleting) (Just . inserting) recur) aligned
|
||||||
|
Loading…
Reference in New Issue
Block a user