HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletext-metrics-0.3.3GHC2021

Data.Text.Metrics

The module provides efficient implementations of various strings metric algorithms. It works with strict Text values.

Note: before version 0.3.0 the package used C implementations of the algorithms under the hood. Beginning from version 0.3.0, the implementations are written in Haskell while staying almost as fast, see:

https://markkarpov.com/post/migrating-text-metrics.html

  • 9 values

Levenshtein variants

4 declarations
valuelevenshtein :: Text -> Text -> Int
#

Return the Levenshtein distance between two Text values. The Levenshtein distance between two strings is the minimal number of operations necessary to transform one string into another. For the Levenshtein distance allowed operations are: deletion, insertion, and substitution.

See also: https://en.wikipedia.org/wiki/Levenshtein_distance.

Heads up, before version 0.3.0 this function returned Data.Numeric.Natural.

Treating inputs like sets

2 declarations

Other

3 declarations
valuejaro :: Text -> Text -> Ratio Int
#

Return the Jaro distance between two Text values. Returned value is in the range from 0 (no similarity) to 1 (exact match).

While the algorithm is pretty clear for artificial examples (like those from the linked Wikipedia article), for arbitrary strings, it may be hard to decide which of two strings should be considered as one having “reference” order of characters (order of matching characters in an essential part of the definition of the algorithm). This makes us consider the first string the “reference” string (with correct order of characters). Thus generally,

jaro a b ≠ jaro b a

This asymmetry can be found in all implementations of the algorithm on the internet, AFAIK.

See also: https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance

Heads up, before version 0.3.0 this function returned Ratio Data.Numeric.Natural.