HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

ModuleDiff-2.0.1Haskell2010

Data.Algorithm.DiffContext

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

Synopsis
  • PackageDiff-2.0.1
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceDiffContext.hs
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.