From 7e75c662dc6b3e8def34c4fc4ba73dce596bec06 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 18 Nov 2015 10:36:19 -0800 Subject: [PATCH] Diagonals. --- src/SES.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SES.hs b/src/SES.hs index 4d3eedfc8..b8875a71d 100644 --- a/src/SES.hs +++ b/src/SES.hs @@ -11,8 +11,13 @@ ses :: Compare a -> [Term a Info] -> [Term a Info] -> [Diff a] ses _ [] b = (Pure . Insert) <$> b ses _ a [] = (Pure . Delete) <$> a ses recur (a : as) (b : bs) = case recur a b of - Just f -> f : ses recur as bs - Nothing -> if SES.cost delete < SES.cost insert then delete else insert where + Just f | SES.cost delete < SES.cost insert && SES.cost delete < SES.cost copy -> delete + | SES.cost insert < SES.cost copy -> insert + | otherwise -> copy + where + copy = f : ses recur as bs + Nothing -> if SES.cost delete < SES.cost insert then delete else insert + where delete = (Pure . Delete $ a) : ses recur as (b : bs) insert = (Pure . Insert $ b) : ses recur (a : as) bs