Commit 217bb9c1 authored by Camil Staps's avatar Camil Staps 🐧

gDiff for RECORD, FIELD and tuples

parent c00e388c
Pipeline #9550 passed with stage
in 1 minute and 47 seconds
......@@ -24,8 +24,9 @@ import StdGeneric
* Compute the {{`Diff`}} between two values.
*/
generic gDiff a :: a a -> [Diff]
derive gDiff Int, UNIT, PAIR, EITHER, OBJECT, CONS of d
derive gDiff []
derive gDiff UNIT, PAIR, EITHER, OBJECT, CONS of d, RECORD of d, FIELD of d
derive gDiff Int, Char, Bool, String
derive gDiff [], (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
/**
* A String representation of a {{`Diff`}} using ANSI escape codes.
......
......@@ -29,11 +29,21 @@ gDiff{|String|} x y = eqDiff x y
gDiff{|UNIT|} UNIT UNIT = []
gDiff{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 ++ fy y1 y2
gDiff{|OBJECT|} fx (OBJECT x) (OBJECT y) = fx x y
gDiff{|CONS of d|} fx (CONS x) (CONS y) =
gDiff{|CONS of d|} fx (CONS x) (CONS y) = let children = fx x y in
[{ status = if (all (\d -> d.status=:Common) children) Common Changed
, value = d.gcd_name
, children = children
}] where children = fx x y
}]
gDiff{|RECORD of d|} fx (RECORD x) (RECORD y) = let children = fx x y in
[{ status = if (all (\d -> d.status=:Common) children) Common Changed
, value = d.grd_name
, children = children
}]
gDiff{|FIELD of d|} fx (FIELD x) (FIELD y) = let children = fx x y in
[{ status = if (all (\d -> d.status=:Common) children) Common Changed
, value = d.gfd_name +++ "="
, children = children
}]
gDiff{|EITHER|} fl fr (LEFT x) (LEFT y) = fl x y
gDiff{|EITHER|} fl fr (RIGHT x) (RIGHT y) = fr x y
gDiff{|EITHER|} fl fr (LEFT x) (RIGHT y) = map (setStatus Removed) (fl x x) ++ map (setStatus Added) (fr y y)
......@@ -49,7 +59,7 @@ eqDiff x y
, {status=Added, value=printToString y, children=[]}
]
derive gDiff []
derive gDiff [], (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
:: PrState =
{ indent :: !Int
......
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