you can define your function using hPrintf and the stdout descriptor.
Thus, the result of the myPrintf function remains an instance of the HPrintfType class
myPrintf:: (HPrintfType c) => String -> c myPrintf = (hPrintf stdout) . (printf "log:%s") main = myPrintf "test %d" (23 :: Int)
The polyvarian form for the printf function only works because you have this instance definition:
(PrintfArg a, PrintfType r) => PrintfType (a -> r).
in each new PrintfArg parameter, enter the output; if possible, enter the class type PrintfType.
The following type will be specified for your log function to work:
logger :: (PrintfType c) => String -> c
but the wil compiler fails because the function returns IO (), not the more general type of the PrintfType class.
In my opinion, only a modification of the Text.Printf module can help you, because you cannot create a new PrintfType instance, because some method is hidden
fp4me source share