1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00
semantic/src/Interpreter.hs

21 lines
515 B
Haskell
Raw Normal View History

2015-11-18 04:15:10 +03:00
module Interpreter (interpret) where
2015-11-18 04:05:16 +03:00
import Algorithm
import Control.Monad.Free
import Control.Comonad.Cofree
import Operation
import Diff
recur :: Term a Info -> Term a Info -> Maybe (Diff a)
recur a b =
run algorithm where
algorithm = Free $ Recursive a b Pure
run :: Algorithm a (Diff a) -> Maybe (Diff a)
run (Pure diff) = Just diff
2015-11-18 04:13:48 +03:00
interpret :: Term a Info -> Term a Info -> Diff a
interpret a b = maybeReplace $ recur a b where
maybeReplace (Just a) = a
maybeReplace Nothing = Just a </> Just b