[project @ 2005-07-11 10:46:42 by simonpj]
authorsimonpj <unknown>
Mon, 11 Jul 2005 10:46:43 +0000 (10:46 +0000)
committersimonpj <unknown>
Mon, 11 Jul 2005 10:46:43 +0000 (10:46 +0000)
Improvements to speakN, define speakNOf, move plural from TcSimplify

ghc/compiler/typecheck/TcSimplify.lhs
ghc/compiler/utils/Outputable.lhs

index c23e798..187634a 100644 (file)
@@ -2348,9 +2348,6 @@ groupErrs report_err (inst:insts)
 addInstLoc :: [Inst] -> Message -> Message
 addInstLoc insts msg = msg $$ nest 2 (pprInstLoc (instLoc (head insts)))
 
-plural [x] = empty
-plural xs  = char 's'
-
 addTopIPErrs :: [Name] -> [Inst] -> TcM ()
 addTopIPErrs bndrs [] 
   = return ()
index a12f46d..d337e7e 100644 (file)
@@ -33,7 +33,7 @@ module Outputable (
        sep, cat, 
        fsep, fcat, 
        hang, punctuate,
-       speakNth, speakNTimes, speakN,
+       speakNth, speakNTimes, speakN, speakNOf, plural,
 
        printSDoc, printErrs, printDump,
        printForC, printForAsm, printForUser,
@@ -476,7 +476,8 @@ speakNth n = hcat [ int n, text suffix ]
     last_dig = n `rem` 10
 
 speakN :: Int -> SDoc
-speakN 1 = ptext SLIT("one")
+speakN 0 = ptext SLIT("none")  -- E.g.  "he has none"
+speakN 1 = ptext SLIT("one")   -- E.g.  "he has one"
 speakN 2 = ptext SLIT("two")
 speakN 3 = ptext SLIT("three")
 speakN 4 = ptext SLIT("four")
@@ -484,10 +485,18 @@ speakN 5 = ptext SLIT("five")
 speakN 6 = ptext SLIT("six")
 speakN n = int n
 
+speakNOf :: Int -> SDoc -> SDoc
+speakNOf 0 d = ptext SLIT("no") <+> d <> char 's'      -- E.g. "no arguments"
+speakNOf 1 d = ptext SLIT("one") <+> d                 -- E.g. "one argument"
+speakNOf n d = speakN n <+> d <> char 's'              -- E.g. "three arguments"
+
 speakNTimes :: Int {- >=1 -} -> SDoc
 speakNTimes t | t == 1            = ptext SLIT("once")
               | t == 2            = ptext SLIT("twice")
-              | otherwise  = int t <+> ptext SLIT("times")
+              | otherwise  = speakN t <+> ptext SLIT("times")
+
+plural [x] = empty
+plural xs  = char 's'
 \end{code}