2015-11-18 03:20:52 +03:00
|
|
|
module Algorithm where
|
2015-11-18 03:24:01 +03:00
|
|
|
|
2016-08-04 02:50:16 +03:00
|
|
|
import Control.Monad.Free.Church
|
2016-08-04 01:12:31 +03:00
|
|
|
import Diff
|
|
|
|
import Prologue
|
|
|
|
import Term
|
|
|
|
|
|
|
|
-- | A single step in a diffing algorithm.
|
|
|
|
data AlgorithmF
|
2016-08-04 01:43:36 +03:00
|
|
|
term -- ^ The type of terms.
|
|
|
|
diff -- ^ The type of diffs.
|
2016-08-04 01:12:31 +03:00
|
|
|
f -- ^ The type representing another level of the diffing algorithm. Often Algorithm.
|
|
|
|
-- | Recursively diff two terms and pass the result to the continuation.
|
2016-08-04 01:43:36 +03:00
|
|
|
= Recursive term term (diff -> f)
|
2016-08-04 01:12:31 +03:00
|
|
|
-- | Diff two arrays and pass the result to the continuation.
|
2016-08-04 01:43:36 +03:00
|
|
|
| ByIndex [term] [term] ([diff] -> f)
|
|
|
|
| ByRandomWalkSimilarity [term] [term] ([diff] -> f)
|
2016-08-04 01:12:31 +03:00
|
|
|
deriving Functor
|
2015-11-18 03:24:01 +03:00
|
|
|
|
2016-02-03 18:28:44 +03:00
|
|
|
-- | A lazily-produced AST for diffing.
|
2016-08-04 02:50:16 +03:00
|
|
|
type Algorithm term diff = F (AlgorithmF term diff)
|
2016-08-04 01:15:18 +03:00
|
|
|
|
2016-08-04 01:43:36 +03:00
|
|
|
recursively :: Term leaf annotation -> Term leaf annotation -> Algorithm (Term leaf annotation) (Diff leaf annotation) (Diff leaf annotation)
|
2016-08-04 01:15:18 +03:00
|
|
|
recursively a b = wrap (Recursive a b pure)
|
2016-08-04 01:38:35 +03:00
|
|
|
|
2016-08-04 01:43:36 +03:00
|
|
|
byIndex :: [Term leaf annotation] -> [Term leaf annotation] -> Algorithm (Term leaf annotation) (Diff leaf annotation) [Diff leaf annotation]
|
2016-08-04 01:38:35 +03:00
|
|
|
byIndex a b = wrap (ByIndex a b pure)
|
2016-08-04 01:40:17 +03:00
|
|
|
|
2016-08-04 01:43:36 +03:00
|
|
|
bySimilarity :: [Term leaf annotation] -> [Term leaf annotation] -> Algorithm (Term leaf annotation) (Diff leaf annotation) [Diff leaf annotation]
|
2016-08-04 01:40:17 +03:00
|
|
|
bySimilarity a b = wrap (ByRandomWalkSimilarity a b pure)
|