preprocessing printf/regex strings (like ocaml)

Oliver George
12 May 2002 12:08:05 +1000

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

    # 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.