Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Typeclass for pretty-printed diffs between two instances of a type.
Derive it for arbitrary sum-of-products types as follows:
data Foo = Foo Int | Bar Bool deriving Generic deriving (Portray, Diff) via Wrapped Generic Foo
If the type of the compared values has a custom Eq instance, the equality comparison used by the Generic derived Diff instance *will differ* from the custom one implemented for the type. It will only check to make sure that the representations of the two types are the same. If you still want the diff algorithm to look into the type, you will need to implement a custom Diff instance alongside the custom Eq instance. If you don't want the diff algorithm to look inside a type, and instead use the custom Eq instance, use:
data Foo = ... instance Diff Foo where diff = diffAtom
Structural Diffs
Structural comparison between values giving a description of differences.
Nothing
Instances
diffAtom :: (Eq a, Portray a) => a -> a -> Maybe Portrayal Source #
Diff on an atomic type, just by using the Eq and Portray instances without using any internal structure of the type.
Atomic Diff
DiffAtom a |
diffVs :: Portrayal -> Portrayal -> Portrayal Source #
Produce a Portrayal
describing a single atomic difference.
Generic
class GDiff a f where Source #
Generic implementation of Diff
.
This is primarily exported to appease Haddock; use via Wrapped Generic T
to access this functionality.
class GDiffRecord f where Source #
Diff record fields, creating docs only for fields that differ.
gdiffRecord :: f x -> f x -> DList (FactorPortrayal Portrayal) Source #
Instances
(GDiffRecord f, GDiffRecord g) => GDiffRecord (f :*: g) Source # | |
Defined in Data.Portray.Diff gdiffRecord :: (f :*: g) x -> (f :*: g) x -> DList (FactorPortrayal Portrayal) Source # | |
(Selector s, Diff a) => GDiffRecord (S1 s (K1 i a :: Type -> Type)) Source # | |
Defined in Data.Portray.Diff gdiffRecord :: S1 s (K1 i a) x -> S1 s (K1 i a) x -> DList (FactorPortrayal Portrayal) Source # |
class GDiffCtor f where Source #
Diff constructor fields, filling equal fields with "_" and reporting whether any diffs were detected.
N.B. this works fine on record constructors, too, in case we want to support configuring whether to use record syntax or constructor application syntax.
This is a separate class from GDiffRecord because it'd be wasteful to accumulate tons of "_" docs for records with lots of fields and then discard them.