Skip to content

Instantly share code, notes, and snippets.

@pocketberserker
Created November 21, 2012 13:54
Show Gist options
  • Save pocketberserker/4124957 to your computer and use it in GitHub Desktop.
Save pocketberserker/4124957 to your computer and use it in GitHub Desktop.
FSharpx.BKTree.(List | ByteString).distance short examples
(*
Reference: http://en.wikipedia.org/wiki/Levenshtein_distance#Example
kitten → sitten (substitution of 's' for 'k')
sitten → sittin (substitution of 'i' for 'e')
sittin → sitting (insertion of 'g' at the end).
*)
open FSharpx.DataStructures
open FSharpx.ByteString
// List
let kitten = "kitten".ToCharArray() |> Array.toList
let sitting = "sitting".ToCharArray() |> Array.toList
assert(BKTree.List.distance kitten sitting = 3)
// ByteString
let kitten = "kitten" |> ByteString.ofString
let sitting = "sitting" |> ByteString.ofString
assert(BKTree.ByteString.distance kitten sitting = 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment