1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00
semantic/src/Algorithm.hs

24 lines
1.0 KiB
Haskell
Raw Normal View History

2015-11-18 03:20:52 +03:00
module Algorithm where
2015-11-18 03:24:01 +03:00
2016-08-04 01:12:31 +03:00
import Diff
import Prologue
import Term
-- | A single step in a diffing algorithm.
data AlgorithmF
a -- ^ The type of leaves in the syntax tree, typically String, but possibly some datatype representing different leaves more precisely.
annotation -- ^ The type of annotations.
f -- ^ The type representing another level of the diffing algorithm. Often Algorithm.
-- | Recursively diff two terms and pass the result to the continuation.
= Recursive (Term a annotation) (Term a annotation) (Diff a annotation -> f)
-- | Diff two arrays and pass the result to the continuation.
| ByIndex [Term a annotation] [Term a annotation] ([Diff a annotation] -> f)
| ByRandomWalkSimilarity [Term a annotation] [Term a annotation] ([Diff a annotation] -> f)
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 01:12:31 +03:00
type Algorithm a annotation = Free (AlgorithmF a annotation)
recursively :: Term leaf annotation -> Term leaf annotation -> Algorithm leaf annotation (Diff leaf annotation)
recursively a b = wrap (Recursive a b pure)