HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

ModuleDiff-2.0.1Haskell2010

Data.Algorithm.DiffContext

Generates a grouped diff with merged runs, and outputs them in the manner of diff -u.

  • 3 types
  • 7 values
  • PackageDiff-2.0.1
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceDiffContext.hs
typetype Hunk c = [Diff [c]]
#

A Hunk is a list of adjacent Diffs.

No two consecutive elements in a Hunk are both applications of First, Second, or Both, i.e. the list does not stutter on Diff constructors.

valuegetContextDiff
  1. :: Eq a
  2. => Maybe ContextSize

    Context size. Nothing means returning a whole-diff Hunk.

  3. -> [a]
  4. -> [a]
  5. -> ContextDiff (Numbered a)
#
> let textA = ["a","b","c","d","e","f","g","h","i","j","k"]
> let textB = ["a","b","d","e","f","g","h","i","j"]
> let diff = getContextDiff (Just 2) textA textB
> prettyContextDiff (text "file1") (text "file2") (text . unnumber) diff
--- file1
+++ file2
@@ -1,5 +1,4 @@
 a
 b
-c
 d
 e
@@ -9,3 +8,2 @@
 i
 j
-k
valuegetContextDiffNumbered
  1. :: Eq a
  2. => Maybe ContextSize

    Context size. Nothing means returning a whole-diff Hunk.

  3. -> [Numbered a]
  4. -> [Numbered a]
  5. -> ContextDiff (Numbered a)
#

Create a diff of separate Hunks, each containing a sequence of differing elements surrounded by common elements for context.

The context size determines when to merge adjacent hunks: two hunks are merged when the number of common elements between them does not exceed twice the context size. Furthermore, if contextSize is Nothing a single hunk with the whole diff is produced.