From 00c3a2ef9f665c5605b2fd221d8a682041b64210 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 18 Mar 2016 12:01:59 -0400 Subject: [PATCH] Spike out a function aligning Terms in Patches. --- src/Alignment.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Alignment.hs b/src/Alignment.hs index d31fde168..3a7a11492 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -14,6 +14,7 @@ import Control.Monad import Control.Monad.Free import Data.Adjoined import Data.Align +import Data.Aligned import Data.Bifunctor.These import Data.Coalescent import Data.Copointed @@ -108,6 +109,13 @@ type Row a = Both (Line a) -- | A fixpoint over a functor. newtype Fix f = Fix { unFix :: f (Fix f) } +alignPatch :: Patch (Term leaf Info) -> Fix (Aligned (Syntax leaf)) +alignPatch (Insert term) = hylo (Fix . AlignThis . pure) unwrap term +alignPatch (Delete term) = hylo (Fix . AlignThat . pure) unwrap term +alignPatch (Replace term1 term2) = let Fix (AlignThis a) = alignPatch $ Delete term1 + Fix (AlignThat b) = alignPatch $ Insert term2 in + Fix (AlignThese a b) + hylo :: Functor f => (f b -> b) -> (a -> f a) -> a -> b hylo phi psi = Alignment.cata phi . ana psi