MyNixOS website logo
Description

Calculate the edit distance between two foldables.

A package to determine the edit distance between two Foldables. These are converted to lists, and the Levenshtein distance determine how many additions, removals and changes are necessary to change the first list into the second list.

levenshtein

Build Status of the package by GitHub actions Build Status of the package by Hackage Hackage version badge

Usage

The module Data.Foldable.Levenshtein exports a data type Edit that represent the possible ways to edit a list by Adding an element, Removing an element, Copying (do nothing with the element), and Swap with a new value.

One can apply such edits to a list with the applyEdits function, for example:

Prelude> applyEdits [Copy 1,Swap 3 4,Swap 0 2,Swap 2 5] [1,3,0,2]
Just [1,4,2,5]

We can also calculate the minimal list of edits necessary to turn one list into another one, for example:

Prelude> levenshtein [1,3,0,2] [1,4,2,5]
(3,[Copy 1,Swap 3 4,Swap 0 2,Swap 2 5])

here it means that the smallest edit distance is three, and that in order to transform [1,3,0,2] to [1,4,2,5] we copy 1 change 3 for 4, change 0 for 2, and change 2 for 5.

Package structure

The package contains one module: Data.Foldable.Levenshtein. This module provides functions to determine the edit distance and a list of edits to turn one Foldable of items to another Foldable of items. The foldables are first converted to a list, so the edits always eventually produce a list of edits, even if (one of) the Foldables is for example a Tree, Maybe, etc.

Besides the Edit object, the module exports three types of functions:

  1. functions that return the edit distance together with a list of reversed edits;
  2. functions that return the edit distance with a list of edits (not reversed); and
  3. functions that only calculate the edit distance, not the edits itself.

The third type is more an optimized version of the first two types since it will take less memory and finish slightly faster.

Some functions allow to specify the penalty for an insertion, deletion, and replacement, and this even per item.

In the table below, we show the different implementations to determine the Levenshtein distance:

EditsEqEquality functionEq
penalty functionsdefault
NormalgenericLevenshteingenericLevenshtein'levenshtein'levenshtein
ReversedgenericReversedLevenshteingenericReversedLevenshtein'reversedLevenshtein'reversedLevenshtein
WithoutgenericLevenshteinDistancegenericLevenshteinDistance'levenshteinDistance'levenshteinDistance

levenshtein is safe Haskell

The levenshtein package does not work with arrays, vectors, etc. but only vanilla lists, making this a safe package.

Contribute

You can contribute by making a pull request on the GitHub repository.

You can contact the package maintainer by sending a mail to [email protected].

Metadata

Version

0.2.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows