diff --git a/Text/Inflections/Ordinal.hs b/Text/Inflections/Ordinal.hs index 7aaf2e8..fe46675 100644 --- a/Text/Inflections/Ordinal.hs +++ b/Text/Inflections/Ordinal.hs @@ -21,7 +21,7 @@ where -- "nd" -- >>> ordinal 10 -- "th" -ordinal :: Integer -> String +ordinal :: Integral a => a -> String ordinal number | remainder100 `elem` [11..13] = "th" | remainder10 == 1 = "st" @@ -41,5 +41,5 @@ ordinal number -- "2nd" -- >>> ordinalize 10 -- "10th" -ordinalize :: Integer -> String +ordinalize :: (Integral a, Show a) => a -> String ordinalize n = show n ++ ordinal n diff --git a/stack.yaml b/stack.yaml index d3d9480..1be6cbc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,3 +1,5 @@ resolver: lts-6.4 packages: - '.' +extra-deps: +- megaparsec-5.0.0 diff --git a/test/Text/Inflections/OrdinalSpec.hs b/test/Text/Inflections/OrdinalSpec.hs index 6200e40..910eb94 100644 --- a/test/Text/Inflections/OrdinalSpec.hs +++ b/test/Text/Inflections/OrdinalSpec.hs @@ -26,38 +26,38 @@ spec = do one :: Spec one = it "returns the ordinal for 1" $ - ordinal 1 `shouldBe` "st" + ordinal (1 :: Integer) `shouldBe` "st" two :: Spec two = it "returns the ordinal for 2" $ - ordinal 2 `shouldBe` "nd" + ordinal (2 :: Integer) `shouldBe` "nd" thousands :: Spec thousands = do it "returns the ordinal for 1002" $ - ordinal 1002 `shouldBe` "nd" + ordinal (1002 :: Integer) `shouldBe` "nd" it "returns the ordinal for 1003" $ - ordinal 1003 `shouldBe` "rd" + ordinal (1003 :: Integer) `shouldBe` "rd" negatives :: Spec negatives = do it "returns the ordinal for -11" $ - ordinal (-11) `shouldBe` "th" + ordinal (-11 :: Integer) `shouldBe` "th" it "returns the ordinal for -1021" $ - ordinal (-1021) `shouldBe` "st" + ordinal (-1021 :: Integer) `shouldBe` "st" fullOrdinals :: Spec fullOrdinals = do it "returns the full ordinal for 1" $ - ordinalize 1 `shouldBe` "1st" + ordinalize (1 :: Integer) `shouldBe` "1st" it "returns the full ordinal for -1021" $ - ordinalize (-1021) `shouldBe` "-1021st" + ordinalize (-1021 :: Integer) `shouldBe` "-1021st" ordinalReturnsNotEmpty :: Spec ordinalReturnsNotEmpty = it "never returns empty" $ property $ - property <$> not . null . ordinal + property <$> not . null . (ordinal :: Integer -> String) ordinalizeContainsTheSameNumber :: Spec ordinalizeContainsTheSameNumber =