preprocessing printf/regex strings (like ocaml)

Hi Haskellers, I'm interested to know why a string translating preprocessor doesn't exist for haskell. It seems to me that it would alleviate printf and regex like problems in an convenient, elegant and type-safe manner. An example of this I came across recently was the ocaml printf statement: # Printf.printf "roar";; roar- : unit = () # Printf.printf "numbers %d %d" 11 23;; numbers 11 23- : unit = () # Printf.printf "a number %d" "word";; This expression has type string but is here used with type int You can see logically how this might work in haskell, compile time evaluation would translate the string into the appropriate native expressions before the statements type is evaluated. I see a similar possibility for regular expression matching, wouldn't it be nice in a haskell script to write: perl like things... msg' = replace "s/love/lust/" msg or, nice regex stuff... main = case match "^(\d+)" of Nothing -> 0 Just (i) -> i the python string notation (str % tuple) would fit really well too... putStrLn "hello %s, you got %d right" % ("oliver", 5) Am I the only one who sees this as being a really valuable extension to haskell? or does it exist and i've just never noticed? cheers, Oliver.

I'm interested to know why a string translating preprocessor doesn't exist for haskell. It seems to me that it would alleviate printf and regex like problems in an convenient, elegant and type-safe manner.
An example of this I came across recently was the ocaml printf statement:
# Printf.printf "roar";; roar- : unit = ()
# Printf.printf "numbers %d %d" 11 23;; numbers 11 23- : unit = ()
# Printf.printf "a number %d" "word";; This expression has type string but is here used with type int
You can see logically how this might work in haskell, compile time evaluation would translate the string into the appropriate native expressions before the statements type is evaluated.
Incidentally, I've written a small functional pearl about implementing printf in Haskell, see http://www.informatik.uni-bonn.de/~ralf/publications.html#J11 Cheers, Ralf
participants (2)
-
Oliver George
-
Ralf Hinze