Change Replace semantics

parent fcdc6dcc
...@@ -192,11 +192,27 @@ instance Eq a => Composable (Replace a) where ...@@ -192,11 +192,27 @@ instance Eq a => Composable (Replace a) where
composable (Replace _ n) (Replace o _) = composable (Replace _ n) (Replace o _) =
check (n == o) "Composing two @Replace@ patches with a different inner value" check (n == o) "Composing two @Replace@ patches with a different inner value"
{- Two semantics are possible for the `Replace old new` patch:
(1) The patch is assumed to only be used on a source which is known
to be equal to `old`.
(2) The patch only replaces `old` by `new` when the source is equal to `old` and
leaves it unchanged otherwise.
Here we choose (2).
-}
instance Eq a => Action (Replace a) a where
act Keep a = a
act (Replace old new) source
| source == old = new
| otherwise = source
{- PRODUCTION instance for semantics (1)
instance Action (Replace a) a where instance Action (Replace a) a where
act Keep a = a act Keep a = a
act (Replace _ n) _ = n act (Replace _ n) _ = n
-}
{- DEBUGGING instance {- DEBUGGING instance for semantics (1)
instance (Show a, Eq a) => Action (Replace a) a where instance (Show a, Eq a) => Action (Replace a) a where
act Keep a = a act Keep a = a
act p@(Replace expected n) found act p@(Replace expected n) found
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment