The edit-distance-vector package

[Tags:bsd3, library, test]

An implementation of the Wagner–Fischer dynamic programming algorithm to find the optimal edit script and cost between two sequences.

The implementation in this package is specialised to sequences represented with Data.Vector but is otherwise agnostic to:

[Skip to Readme]


Versions 1.0,,,,
Change log
Dependencies base (>=4.5 && <5.0), vector (>=0.8) [details]
License BSD3
Copyright (c) 2015 Thomas Sutton and others.
Author Thomas Sutton
Category Data, Data Structures, Algorithms
Home page
Bug tracker
Source repository head: git clone
Uploaded Tue May 24 03:49:20 UTC 2016 by ThomasSutton
Distributions LTSHaskell:, NixOS:, Stackage:, Tumbleweed:
Downloads 679 total (11 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2016-05-24 [all 1 reports]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for edit-distance-vector

Readme for edit-distance-vector-

Edit Distance: Vector

Build Status

This is a small library for calculating the edit distance and edit script between two vectors. It is generic enough that you should be able to use it with vectors containing values of any type you like, with changes described by any type you like, and with costs represented by any type you like (with a few restrictions).


The edit-distance-vector package is a normal Haskell library and can be installed using the Cabal package management tool.

cabal update
cabal install edit-distance-vector

edit-distance-vector is automatically tested on GHC versions 7.4.2, 7.6.3, 7.8.3, 7.10.1, 8.0.2 using the Travis CI service.


The interface to edit-distance-vector is very small; just import Data.Vector.Distance, create a Params value with the correct operations to deal with your types, and pass this to leastChanges along with your Vectors.

import           Data.Monoid

import qualified Data.Vector          as V
import           Data.Vector.Distance

-- | Editing vectors of 'Char' values, with '(String, Int, Char)' describing
--   changes, and the additive monoid of 'Int' describing costs.
str :: Params Char (String, Int, Char) (Sum Int)
str = Params
    { equivalent = (==)
    , delete     = \i c    -> ("delete", i, c)
    , insert     = \i c    -> ("insert", i, c)
    , substitute = \i c c' -> ("replace", i, c')
    , cost = const (Sum 1)
    , positionOffset = \ (op, _, _) -> if op == "delete" then 0 else 1

main :: IO ()
main = do
    print $ leastChanges str (V.fromList "I am thomas")
                             (V.fromList "My name is Thomas")

(See test/sample.hs for a version of this code that is compiled by the automated test suite.)