1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00
semantic/src/Patch.hs
2015-11-30 19:08:28 -05:00

21 lines
459 B
Haskell

module Patch where
data Patch a =
Replace a a
| Insert a
| Delete a
deriving (Functor, Show, Eq)
after :: Patch a -> Maybe a
after (Replace _ a) = Just a
after (Insert a) = Just a
after _ = Nothing
before :: Patch a -> Maybe a
before (Replace a _) = Just a
before (Delete a) = Just a
before _ = Nothing
patchSum :: (a -> Integer) -> Patch a -> Integer
patchSum termCost patch = (maybe 0 termCost $ before patch) + (maybe 0 termCost $ after patch)