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

Add constructors to retrieve the edit graph & equality function.

This commit is contained in:
Rob Rix 2017-03-10 13:03:09 -05:00
parent b373e4c63e
commit cd61576be9

View File

@ -19,6 +19,8 @@ data State s a where
data StepF element result where data StepF element result where
M :: MyersF a b -> StepF a b M :: MyersF a b -> StepF a b
S :: State MyersState b -> StepF a b S :: State MyersState b -> StepF a b
GetGraph :: StepF a (EditGraph a)
GetEq :: StepF a (a -> a -> Bool)
type Myers a = Freer (StepF a) type Myers a = Freer (StepF a)
@ -33,14 +35,14 @@ data Direction = Forward | Reverse
-- Evaluation -- Evaluation
runMyers :: Myers a b -> b runMyers :: (a -> a -> Bool) -> EditGraph a -> Myers a b -> b
runMyers = runAll $ MyersState (Vector.replicate 100 0) (Vector.replicate 100 0) runMyers eq graph = runAll $ MyersState (Vector.replicate 100 0) (Vector.replicate 100 0)
where runAll state step = case runMyersStep state step of where runAll state step = case runMyersStep eq graph state step of
Left a -> a Left a -> a
Right next -> uncurry runAll next Right next -> uncurry runAll next
runMyersStep :: MyersState -> Myers a b -> Either b (MyersState, Myers a b) runMyersStep :: (a -> a -> Bool) -> EditGraph a -> MyersState -> Myers a b -> Either b (MyersState, Myers a b)
runMyersStep state step = case step of runMyersStep eq graph state step = case step of
Return a -> Left a Return a -> Left a
Then step cont -> case step of Then step cont -> case step of
M myers -> Right (state, decompose myers >>= cont) M myers -> Right (state, decompose myers >>= cont)
@ -48,6 +50,9 @@ runMyersStep state step = case step of
S Get -> Right (state, cont state) S Get -> Right (state, cont state)
S (Put state') -> Right (state', cont ()) S (Put state') -> Right (state', cont ())
GetGraph -> Right (state, cont graph)
GetEq -> Right (state, cont eq)
decompose :: MyersF a b -> Myers a b decompose :: MyersF a b -> Myers a b
decompose myers = case myers of decompose myers = case myers of