generic-diff: Generic structural diffs

[ bsd3, generics, library, test ] [ Propose Tags ] [ Report a vulnerability ]

Generic structural diffs on arbitrary datatypes, using generics-sop.

See the module documentation in Generics.Diff.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.12 && <5), generics-sop (>=0.4 && <0.6), sop-core (>=0.4.0.1 && <0.6), text (>=1.1 && <2.2) [details]
Tested with ghc ==9.12.2, ghc ==9.10.1, ghc ==9.8.2, ghc ==9.6.5, ghc ==9.4.8, ghc ==9.2.8, ghc ==9.0.2, ghc ==8.10.7, ghc ==8.6.5
License BSD-3-Clause
Copyright Copyright(c) Frederick Pringle 2025
Author Frederick Pringle
Maintainer freddyjepringle@gmail.com
Category Generics, Test
Home page https://github.com/fpringle/generic-diff
Source repo head: git clone https://github.com/fpringle/generic-diff.git
Uploaded by fpringle at 2025-05-30T19:46:22Z
Distributions
Downloads 5 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for generic-diff-0.1.0.0

[back to package description]

Haskell CI

Generic structural diffs

generic-diff lets us pinpoint exactly where two values differ, which can be very useful, for example for debugging failing tests. This functionality is provided by the Diff typeclass, for which instances can be derived automatically using Generic from generics-sop.

For detailed information, see the Hackage docs.

Example

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

import Generics.Diff
import Generics.Diff.Render

import qualified GHC.Generics as G
import qualified Generics.SOP as SOP

data BinOp = Plus | Minus
  deriving stock (Show, G.Generic)
  deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo, Diff)

data Expr
  = Atom Int
  | Bin {left :: Expr, op :: BinOp, right :: Expr}
  deriving stock (Show, G.Generic)
  deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo, Diff)

expr1, expr2 :: Expr
expr1 = Bin (Atom 1) Plus (Bin (Atom 1) Plus (Atom 1))
expr2 = Bin (Atom 1) Plus (Bin (Atom 1) Plus (Atom 2))
ghci> printDiffResult $ diff expr1 expr2
In field right:
  Both values use constructor Bin but fields don't match
  In field right:
    Both values use constructor Atom but fields don't match
    In field 0 (0-indexed):
      Not equal