All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scalaz.MetricSpace.scala Maven / Gradle / Ivy

The newest version!
package scalaz

/**
 * 
    *
  1. (distance(a, b) == 0) == (a == b)
  2. *
  3. Commutativity: distance(a, b) == distance(b, a)
  4. *
  5. Triangle Equality: distance(a, b) + distance(b, c) >= distance(a, c)
  6. *
*/ sealed trait MetricSpace[-A] { def distance(a1: A, a2: A): Int } trait MetricSpaces { def metricSpace[A](f: (A, A) => Int): MetricSpace[A] = new MetricSpace[A] { def distance(a1: A, a2: A) = f(a1, a2) } import Scalaz._ def levenshtein[M[_], A](implicit l: Length[M], i: Index[M], e: Equal[A]): MetricSpace[M[A]] = metricSpace[M[A]](_ <---> _) implicit def levenshteins: MetricSpace[String] = levenshtein[List, Char] ∙ ((s: String) => s.toList) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy