Created
May 17, 2013 19:33
-
-
Save tixxit/5601424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final case class Epsilon[A](value: A) | |
| object Epsilon { | |
| def apply[A: Field](x: Double): A = Field[A].fromDouble(x) | |
| } | |
| // This can be part of the MetricSpace ops. | |
| implicit class ApproxEq[A](x: A) { | |
| def =~=[B](y: A)(implicit ms: MetricSpace[A, B], e: Epsilon[B], o: Order[B]): Boolean = | |
| MetricSpace.close(x, y)(ms, e, o) | |
| } | |
| // In algebra/MetricSpace.scala | |
| object MetricSpace { | |
| def close[A, B](x: A, y: A)(implicit ms: MetricSpace[A, B], e: Epsilon[B], o: Order[B]): Boolean = { | |
| ms.distance(x, y) < e.value | |
| } | |
| implicit def trivialMetricSpace[A: IsReal: Rng] = new MetricSpace[A, A] { | |
| def distance(x: A, y: A): A = (x - y).abs | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples:
I think we'd actually want to somehow tie Epsilon to both types in the MEtricSpace too....