[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:31 UTC 2010


The following commit has been merged in the master branch:
commit 93ee68bf4065b7a1efe64ea1a2899133e6c47b1f
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sun Nov 14 08:13:14 2004 +0100

    Checkpointing with working printf/fprintf
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-35)

diff --git a/ChangeLog b/ChangeLog
index 50e98bb..1ca5e16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,18 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-14 01:13:14 GMT	John Goerzen <jgoerzen at complete.org>	patch-35
+
+    Summary:
+      Checkpointing with working printf/fprintf
+    Revision:
+      missingh--head--0.5--patch-35
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/Printf.hs
+
+
 2004-11-14 00:31:43 GMT	John Goerzen <jgoerzen at complete.org>	patch-34
 
     Summary:
diff --git a/libsrc/MissingH/Printf.hs b/libsrc/MissingH/Printf.hs
index 4fad406..c512fe4 100644
--- a/libsrc/MissingH/Printf.hs
+++ b/libsrc/MissingH/Printf.hs
@@ -31,20 +31,26 @@ This module provides various helpful utilities for using a C-style printf().
 Written by John Goerzen, jgoerzen\@complete.org
 -}
 
-module MissingH.Printf(
+module MissingH.Printf(-- * Variable-Argument Ouptut
+                       vsprintf,
+                       vprintf,
+                       vfprintf,
+                       -- * List-Argument Output
+                       sprintf,
+                       printf,
+                       fprintf,
+                       -- * Utility Function
+                       v,
+                       -- * Underlying Types
                        Value(..),
-                       PFRun(..),
+                       PFRun,
                        PFType(..),
-                       sprintf,
-                       sprintf_real,
---                       ssprintf,
---                       printf,
-                       wrapper,
-                       v
+                       IOPFRun,
                        ) where
 
 import MissingH.Str
 import Data.List
+import System.IO
 
 data Value =
            ValueInt Int
@@ -65,43 +71,47 @@ instance PFType String where
     fromValue (ValueString x) = x
     fromValue _ = error "fromValue string"
 
+{-
 instance PFType Value where
     toValue = id
     fromValue = id
+-}
 
 v :: PFType a => a -> Value
 v = toValue
 
 class PFRun a where
     pfrun :: ([Value] -> String) -> a
-
 instance PFRun String where
     pfrun f = f $ []
-
 instance (PFType a, PFRun b) => PFRun (a -> b) where
     pfrun f x = pfrun (\xs -> f (toValue x : xs))
 
-sprintf_real :: String -> [Value] -> String
-
-sprintf_real [] [] = []
-sprintf_real ('%' : xs) (y : ys) = (fromValue y) ++ sprintf_real xs ys
-sprintf_real ('!' : xs) (y : ys) = 
-    show (((fromValue y)::Int) + 1) ++ sprintf_real xs ys
-sprintf_real (x:xs) y = x : sprintf_real xs y
-
-forcestring :: String -> String
-forcestring x = x
+class IOPFRun a where
+    iopfrun :: Handle -> ([Value] -> String) -> a
+instance IOPFRun (IO ()) where
+    iopfrun h f = hPutStr h $ pfrun f
+instance (PFType a, IOPFRun b) => IOPFRun (a -> b) where
+    iopfrun h f x = iopfrun h (\xs -> f (toValue x : xs))
 
-wrapper :: String -> [Value] -> Value
-wrapper f v = toValue $ sprintf_real f v
+sprintf :: String -> [Value] -> String
+sprintf [] [] = []
+sprintf ('%' : xs) (y : ys) = (fromValue y) ++ sprintf xs ys
+sprintf ('!' : xs) (y : ys) = 
+    show (((fromValue y)::Int) + 1) ++ sprintf xs ys
+sprintf (x:xs) y = x : sprintf xs y
 
-sprintf :: (PFRun a) => String -> a
-sprintf f = pfrun $ sprintf_real f
+vsprintf :: (PFRun a) => String -> a
+vsprintf f = pfrun $ sprintf f
 
---printf :: (PFRun a) => String -> IO a
---printf = return . sprintf
+fprintf :: Handle -> String -> [Value] -> IO ()
+fprintf h f v = hPutStr h $ sprintf f v
 
---printf :: (PFRun a) => String -> a
+printf :: String -> [Value] -> IO ()
+printf f v = fprintf stdout f v
 
---printf :: PFRun a => String -> a -> IO ()
+vfprintf :: IOPFRun a => Handle -> String -> a
+vfprintf h f = iopfrun h $ sprintf f
 
+vprintf :: IOPFRun a => String -> a
+vprintf f = vfprintf stdout f

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list