-- The first argument indicates whether numbers up to ten should be
-- printed "verbose"
ordinal :: Bool -> Int -> String
ordinal b i
    | i >= 1 && i <= 10 && b = table !! (i - 1)
    | i >= 0                 = show i ++ extension i
    | otherwise              = internalError "Messages.hs"
                                             "ordinal"
                                             "can't show numbers smaller than 0"
    where
        table =
            [ "first", "second", "third", "fourth", "fifth", "sixth","seventh"
            , "eighth", "ninth", "tenth"
            ]
        extension j
            | j > 3 && i < 20 = "th"
            | j `mod` 10 == 1 = "st"
            | j `mod` 10 == 2 = "nd"
            | j `mod` 10 == 3 = "rd"
            | otherwise       = "th"
ordinal :: Bool -> Int -> String
ordinal b i
    | i >= 1 && i <= 10 && b = table !! (i - 1)
    | i >= 0                 = show i ++ extension i
    | otherwise              = internalError "Messages.hs"
                                             "ordinal"
                                             "can't show numbers smaller than 0"
    where
        table =
            [ "first", "second", "third", "fourth", "fifth", "sixth","seventh"
            , "eighth", "ninth", "tenth"
            ]
        extension j
            | j > 3 && i < 20 = "th"
            | j `mod` 10 == 1 = "st"
            | j `mod` 10 == 2 = "nd"
            | j `mod` 10 == 3 = "rd"
            | otherwise       = "th"
ordinal b i
    | i >= 1 && i <= 10 && b = table !! (i - 1)
    | i >= 0                 = show i ++ extension i
    | otherwise              = internalError "Messages.hs"
                                             "ordinal"
                                             "can't show numbers smaller than 0"
    where
        table =
            [ "first", "second", "third", "fourth", "fifth", "sixth","seventh"
            , "eighth", "ninth", "tenth"
            ]
        extension j
            | j > 3 && i < 20 = "th"
            | j `mod` 10 == 1 = "st"
            | j `mod` 10 == 2 = "nd"
            | j `mod` 10 == 3 = "rd"
            | otherwise       = "th"