preprocessing printf/regex strings (like ocaml)

David Feuer dfeuer@cs.brown.edu
Sat, 11 May 2002 23:27:20 -0400


On Sun, May 12, 2002, Oliver George wrote:
> perl like things...
> 
>     msg' = replace "s/love/lust/" msg
> 
> or, nice regex stuff...
> 
>     main = case match "^(\d+)" of
>              Nothing  -> 0
>              Just (i) -> i
> 


Ick!  regexes can be handled much better than that.  Imagine something
like:


q = case x of
        /"^$" -> "Empty Line."
        /"^(foo@\d+)" -> foo ++ "hello!"
        /"confusion (foo@?) (bar@*)" -> "foo is" ++ foo ++ "And bar is"
                                                ++bar
        /"(a@*)" -> error "Sorry: I don't know what to do with "++a

I don't know if this sort of syntax could work, but something similar
would seem sensible.  If it's not clear:  the regex is used as a
pattern.  If it matches the string, that path is taken in the case
statement.  Also, wherever there are parenthesis with a "variable @",
that variable is bound to the relevent string portion.



> the python string notation (str % tuple) would fit really well too...
> 
>     putStrLn "hello %s, you got %d right" % ("oliver", 5)

Might be nice.

> 
> 
> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-- 
Night.  An owl flies o'er rooftops.  The moon sheds its soft light upon
the trees.
David Feuer