From cefd594191bb116792252acc94b453293e193643 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 24 Feb 2017 09:12:37 -0500 Subject: [PATCH] Define small-step interpretation in terms of decompose. --- src/Interpreter.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 31819e74a..f4211439b 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -2,6 +2,7 @@ module Interpreter (diffTerms) where import Algorithm +import Control.Applicative.Free import Data.Align.Generic import Data.Functor.Both import Data.Functor.Classes @@ -12,7 +13,7 @@ import Data.These import Diff import Info import Patch (Patch, inserting, deleting, replacing, patchSum) -import Prologue hiding (lookup) +import Prologue hiding (lookup, Pure) import Syntax as S import Term @@ -108,6 +109,15 @@ runAlgorithm recur = iterAp $ \ r cont -> case r of Replace a b -> cont (replacing a b) where maybeRecur a b = if comparable a b then Just (recur (These a b)) else Nothing + +runStep :: (Eq leaf, HasField fields Category, HasField fields (Maybe FeatureVector)) + => Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result + -> Either result (Algorithm (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result) +runStep = \case + Pure a -> Left a + Ap algorithm cont -> Right $ cont <*> decompose algorithm + + -- | Decompose a step of an algorithm into the next steps to perform. decompose :: (Eq leaf, HasField fields Category, HasField fields (Maybe FeatureVector)) => AlgorithmF (SyntaxTerm leaf fields) (SyntaxDiff leaf fields) result -- ^ The step in an algorithm to decompose into its next steps.