[Haskell-cafe] untyped printf

Ben Franksen ben.franksen at online.de
Fri Dec 4 17:50:02 UTC 2020

I am writing an interpreter for a very simple untyped language and I
want to provide a built-in function to format a list of values in a
printf like fashion. There is the beautiful Text.Printf module with its
multi-variadic printf function, and I would like to use that to do all
the heavy lifting.

I can easily implement an

  instance PrintfArg Value

for my Value type, but what I need in addition to that is an "untyped"
version of printf i.e. something like

  format :: String -> [Value] -> String

with the property that

  format fmt [] = printf fmt
  format fmt [x] = printf fmt x
  format fmt [x,y] = printf fmt x y

I am pretty sure this is possible using a bit of class hackery and
perhaps GADTs or continuation passing thrown in, but I can't seem to get
it working. Any hint that helps to untangle the knots in my brain would
be appreciated!


More information about the Haskell-Cafe mailing list