This is a difficult problem more than a useful problem (I spent several hours on it). Given some features,
put_debug, put_err :: String -> IO ()
put_foo :: String -> StateT [String] m ()
I want to write a generic printf function, call it gprint so I can write
pdebug = gprint put_debug
perr = gprint put_err
pfoo = gprint put_foo
and then use pdebug, perrand pfoolike printf, for example,
pdebug "Hi"
pdebug "my value: %d" 1
pdebug "two values: %d, %d" 1 2
I am unable to find a sufficiently general class. My attempts were such as (for those who are familiar with printf, or Oleg's variational function method)
class PrintfTyp r where
type AppendArg r a :: *
spr :: (String -> a) -> String -> [UPrintf] -> AppendArg r a
or
class PrintfTyp r where
type KRetTyp r :: *
spr :: (String -> KRetTyp r) -> String -> [UPrintf] -> r
: r ( AppendArg), , instance PrintfTyp a, ( ).
, : , . , . !!