[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:46:35 UTC 2010
The following commit has been merged in the master branch:
commit 084dd7e8374a1ef6ad54d642dfb08673e0fbce63
Author: John Goerzen <jgoerzen at complete.org>
Date: Mon Nov 15 06:38:38 2004 +0100
The printer compiles
Keywords:
(jgoerzen at complete.org--projects/missingh--head--0.5--patch-38)
diff --git a/ChangeLog b/ChangeLog
index be68ac4..40d1e51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
#
+2004-11-14 23:38:38 GMT John Goerzen <jgoerzen at complete.org> patch-38
+
+ Summary:
+ The printer compiles
+ Revision:
+ missingh--head--0.5--patch-38
+
+
+ modified files:
+ ChangeLog libsrc/MissingH/Printf/Printer.lhs
+ libsrc/MissingH/Printf/Types.lhs
+
+
2004-11-14 23:09:10 GMT John Goerzen <jgoerzen at complete.org> patch-37
Summary:
diff --git a/libsrc/MissingH/Printf/Printer.lhs b/libsrc/MissingH/Printf/Printer.lhs
index 9afe164..b6f5027 100644
--- a/libsrc/MissingH/Printf/Printer.lhs
+++ b/libsrc/MissingH/Printf/Printer.lhs
@@ -45,8 +45,9 @@ get_conversion_func c = fromMaybe (error (c:": CF unknown")) $ lookup c cfs
-- %d, %i
print_signed_int :: ConversionFunc
-print_signed_int arg flags mw mp = res
- where preci = fromMaybe 1 mp
+print_signed_int argv flags mw mp = res
+ where arg = (fromValue argv)::Integer
+ preci = read (fromMaybe "1" mp)
width = fromMaybe 0 mw
disp | Thousands `elem` flags = thousandify . show
| otherwise = show
@@ -67,8 +68,9 @@ print_signed_int arg flags mw mp = res
-- %o, u, x, X
print_unsigned_int :: Char -> ConversionFunc
-print_unsigned_int base arg flags mw mp = res
- where preci = fromMaybe 1 mp
+print_unsigned_int base argv flags mw mp = res
+ where arg = (fromValue argv)::Integer
+ preci = read (fromMaybe "1" mp)
width = fromMaybe 0 mw
w = if ZeroPadded `elem` flags then (read preci) `max` width
else read preci
@@ -96,8 +98,9 @@ print_unsigned_int base arg flags mw mp = res
-- %e, E
print_exponent_double :: Char -> ConversionFunc
-print_exponent_double e arg flags mw mp = res
- where preci = fromMaybe 6 mp
+print_exponent_double e argv flags mw mp = res
+ where arg = (fromValue argv)::Double
+ preci = read (fromMaybe "6" mp)
width = fromMaybe 0 mw
plus_sign = if Plus `elem` flags
then "+"
@@ -106,9 +109,9 @@ print_exponent_double e arg flags mw mp = res
else ""
keep_dot = AlternateForm `elem` flags
res = let to_show = (fromRational $ toRational arg) :: Double
- shown = showEFloat (Just $preci) (abs to_show) ""
+ shown = showEFloat (Just (read preci)) (abs to_show) ""
sign = if to_show < 0 then "-" else plus_sign
- fix_prec0 = if preci == 0
+ fix_prec0 = if (read preci) == 0
then case break (== '.') shown of
(xs, _:_:ys)
| keep_dot -> xs ++ '.':ys
@@ -121,15 +124,16 @@ print_exponent_double e arg flags mw mp = res
fix_exp = case break (== 'e') fix_exp_sign of
(xs, [_,s,y]) -> xs ++ [e,s,'0',y]
(xs, _:ys) -> xs ++ e:ys
- num_zeroes = (width - length fix_exp - length sign)
+ num_zeroes = (width - genericLength fix_exp - genericLength sign)
`max` 0
- in sign ++ replicate num_zeroes '0' ++ fix_exp
+ in sign ++ genericReplicate num_zeroes '0' ++ fix_exp
-- %f, F
print_fixed_double :: Char -> ConversionFunc
-print_fixed_double f arg flags mw mp = res
- where preci = fromMaybe 6 mp
+print_fixed_double f argv flags mw mp = res
+ where arg = (fromValue argv)::Double
+ preci = read (fromMaybe "6" mp)
width = fromMaybe 0 mw
plus_sign = if Plus `elem` flags
then "+"
@@ -140,29 +144,30 @@ print_fixed_double f arg flags mw mp = res
fix_case | f == 'f' = map toLower
| otherwise = map toUpper
res = let to_show = (fromRational $ toRational arg) :: Double
- shown = showFFloat (Just preci) (abs to_show) ""
- shown' = if add_dot && preci == 0 then shown ++ "."
+ shown = showFFloat (Just (read preci)) (abs to_show) ""
+ shown' = if add_dot && (read preci) == 0 then shown ++ "."
else shown
sign = if to_show < 0 then "-" else plus_sign
- num_zeroes = (width - length shown' - length sign)
+ num_zeroes = (width - genericLength shown' - genericLength sign)
`max` 0
- in sign ++ replicate num_zeroes '0' ++ fix_case shown'
+ in sign ++ genericReplicate num_zeroes '0' ++ fix_case shown'
-- %c, C
print_char :: ConversionFunc
-print_char arg _ _ _ = [arg]
+print_char arg _ _ _ = [(fromValue arg)::Char]
-- %s, S
print_string :: ConversionFunc
-print_string arg _ _ mp
+print_string argv _ _ mp
= case mp of
- Just preci -> if preci < 0 then arg else take preci arg
+ Just preci -> if (read preci) < 0 then arg else take (read preci) arg
Nothing -> arg
+ where arg = fromValue argv
-- Corresponds to %H (Haskell extension)
show_arg :: ConversionFunc
-show_arg arg flags mw mp = (print_string show arg) flags mw mp
+show_arg argv flags mw mp = (print_string (toValue (show argv))) flags mw mp
lower_hex, upper_hex :: Bool
lower_hex = False
diff --git a/libsrc/MissingH/Printf/Types.lhs b/libsrc/MissingH/Printf/Types.lhs
index 4623917..2d3ee46 100644
--- a/libsrc/MissingH/Printf/Types.lhs
+++ b/libsrc/MissingH/Printf/Types.lhs
@@ -7,7 +7,10 @@ import System.IO
data Value =
ValueInt Int
+ | ValueInteger Integer
| ValueString String
+ | ValueChar Char
+ | ValueDouble Double
deriving (Eq, Show)
class PFType a where
@@ -19,11 +22,26 @@ instance PFType Int where
fromValue (ValueInt x) = x
fromValue _ = error "fromValue int"
+instance PFType Integer where
+ toValue = ValueInteger
+ fromValue (ValueInteger x) = x
+ fromValue _ = error "fromValue integer"
+
instance PFType String where
toValue = ValueString
fromValue (ValueString x) = x
fromValue _ = error "fromValue string"
+instance PFType Char where
+ toValue = ValueChar
+ fromValue (ValueChar x) = x
+ fromValue _ = error "fromValue char"
+
+instance PFType Double where
+ toValue = ValueDouble
+ fromValue (ValueDouble x) = x
+ fromValue _ = error "fromValue Double"
+
{-
instance PFType Value where
toValue = id
@@ -59,7 +77,7 @@ data Format = Literal String
| CharCount
type ArgNum = Integer
-type Arg = String
+type Arg = Value
type Width = Integer
type Precision = String
data Flag = AlternateForm -- "#"
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list