HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleDiff-1.0.2Haskell2010

Data.Algorithm.DiffContext

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

  • 3 types
  • 8 values
  • PackageDiff-1.0.2
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceDiffContext.hs
valuegetContextDiff
  1. :: Eq a
  2. => Maybe Int

    Number of context elements, Nothing means infinite

  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
valuegroupBy' :: (a -> a -> Bool) -> [a] -> [[a]]
#

A version of groupBy that does not assume the argument function is transitive. This is used to partition the Diff list into segments that begin and end with matching (Both) text, with and have non-matching (First and Second) text in the middle.

let notBoth1 a b = not (a == 1 || b == 1) in

groupBy' notBoth1 [1,1,2,3,1,1,4,5,6,1]
[[1],[1,2,3,1],[1,4,5,6,1]]

groupBy notBoth1 [1,1,2,3,1,1,4,5,6,1]
[[1],[1,2,3],[1],[1,4,5,6],[1]]

In the first result the list is split anywhere there are two adjacent ones, as desired.