ms 0.1 → 0.2
raw patch · 3 files changed
+24/−18 lines, 3 files
Files
- ms.cabal +6/−3
- src/Math/MetricSpace.hs +9/−9
- tests/test.hs +9/−6
ms.cabal view
@@ -1,5 +1,5 @@ name: ms-version: 0.1+version: 0.2 synopsis: metric spaces description: A 'MetricSpace' is a set together with a notion of distance between@@ -7,12 +7,15 @@ four laws: . (1) __non-negative__: @forall x y. 'dist' x y >= 0@+ . (2) __identity of indiscernibles__: @forall x y. 'dist' x y == 0 \<=\> x == y@+ . (3) __symmetry__: @forall x y. dist x y == 'dist' y x@+ . (4) __triangle inequality__: @forall x y z. 'dist' x z <= 'dist' x y + 'dist' y z@ .- See the Wikipedia <https://en.wikipedia.org/wiki/Metric_space article on- metric spaces> for more details.+ See the Wikipedia <https://en.wikipedia.org/wiki/Metric_space article on metric spaces>+ for more details. homepage: https://github.com/relrod/ms license: BSD2
src/Math/MetricSpace.hs view
@@ -23,8 +23,8 @@ -- (3) __symmetry__: @forall x y. dist x y == 'dist' y x@ -- (4) __triangle inequality__: @forall x y z. 'dist' x z <= 'dist' x y + 'dist' y z@ ----- See the Wikipedia <https://en.wikipedia.org/wiki/Metric_space article on--- metric spaces> for more details.+-- See the Wikipedia <https://en.wikipedia.org/wiki/Metric_space article on metric spaces>+-- for more details. ---------------------------------------------------------------------------- module Math.MetricSpace where @@ -139,14 +139,14 @@ -- | Levenshtein distance between 'String's. -- -- >>> dist levenshtein "foo" "bar"--- 3.0+-- 3 -- -- >>> dist levenshtein "hi" "ha"--- 1.0+-- 1 -- -- >>> dist levenshtein "ff" "ff"--- 0.0-levenshtein :: Floating b => MetricSpace String b+-- 0+levenshtein :: Integral b => MetricSpace String b levenshtein = MetricSpace (\a b -> fromIntegral $ levenshteinDistance defaultEditCosts a b) {-# INLINE levenshtein #-}@@ -154,11 +154,11 @@ -- | Discrete distance over n-dimensional 'Vector's. -- -- >>> dist discrete (V.fromList [3,4]) (V.fromList [3,4])--- 0.0+-- 0 -- -- >>> dist discrete (V.fromList [1,49]) (V.fromList [3,-94])--- 1.0-discrete :: (Eq a, Floating b) => MetricSpace (V.Vector a) b+-- 1+discrete :: (Eq a, Integral b) => MetricSpace (V.Vector a) b discrete = MetricSpace (\a b -> if a == b then 0 else 1) {-# INLINE discrete #-}
tests/test.hs view
@@ -69,17 +69,20 @@ [ genTestGroup "levenshtein" levenshtein + -- Integer+ , testGroup "Integer" [+ genTestGroupV "discrete" (discrete :: MetricSpace (V.Vector Integer) Integer)+ ]+ -- Double , testGroup "Double" [- genTestGroupV "discrete" (discrete :: MetricSpace (V.Vector Double) Double)- , genTestGroupV "euclidean" (euclidean :: MetricSpace (V.Vector Double) Double)- , genTestGroupV "taxicab" (taxicab :: MetricSpace (V.Vector Double) Double)+ genTestGroupV "euclidean" (euclidean :: MetricSpace (V.Vector Double) Double)+ , genTestGroupV "taxicab" (taxicab :: MetricSpace (V.Vector Double) Double) ] -- Float , testGroup "Float" [- genTestGroupV "discrete" (discrete :: MetricSpace (V.Vector Float) Float)- , genTestGroupV "euclidean" (euclidean :: MetricSpace (V.Vector Float) Float)- , genTestGroupV "taxicab" (taxicab :: MetricSpace (V.Vector Float) Float)+ genTestGroupV "euclidean" (euclidean :: MetricSpace (V.Vector Float) Float)+ , genTestGroupV "taxicab" (taxicab :: MetricSpace (V.Vector Float) Float) ] ]